Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by somejonus · Apr 25, 2017 at 05:55 PM · iosfacebookapigraph

How to post as Page using the Facebook SDK

I'm trying to post to a Facebook page AS the page using the Unity Facebook SDK running on iOS. As I understand, to do that, I need the pages access token with manage_pages and publish_pages. I know that I can get it from /me/accounts?fields=access_token, but how do I tell AccessToken.CurrentAccessToken to use my pages access token instead?

Right now i'm using the following:

 var wwwForm = new WWWForm();
 //wwwForm.AddField ("access_token", "A-T I NEED");
 wwwForm.AddBinaryData("image", screenshot, "InteractiveConsole.png");
 wwwForm.AddField("message", "herp derp.  I did a thing!  Did I do this right?");
 FB.API("/PAGE-ID/photos", HttpMethod.POST, HandleResult, wwwForm);

I tried putting the access token manually, but that didn't work (so I commented it out).

With this as it is I'm getting an error, telling me that I need publish_actions, wich is not correct since I'm not trying to post as the user. If I also get publish_actions the post goes online, but is posted to the page as the user speaking. (User is also Admin)

Any Ideas ? Thanks!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by PieterAlbers · Jun 13, 2017 at 02:02 PM

Did you solve this - I am can't get it to work properly either. Thanks, Pieter

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image somejonus · Jun 13, 2017 at 02:05 PM 0
Share

I did. I answered this over at Stack Overflow:

https://stackoverflow.com/questions/43585245/changing-currentaccesstoken-in-facebook-unity-sdk

avatar image AmrmHady · Sep 16, 2017 at 10:48 AM 0
Share

Do you happen to know how can I post it inside an Album, in here graphApi/page/photos it says the "aid" parameter is deprecated

or how can I even move it to an album. thanks to ur UnityWebRequest solution I could finally post as a page , but the photos are uploaded to the timeline album , cant change it anyhow.

avatar image somejonus AmrmHady · Sep 16, 2017 at 11:22 AM 0
Share

Well, I don't have a lot time right now. But maybe this might help. On thing is to post to an Album by creating it, the other is getting the id of that album so you don't create a new album with the same name every time you upload to it. Probably not the best or easiest way to do it, but it works. Here you go:

 // ALBU$$anonymous$$ NA$$anonymous$$E //

 [System.Serializable]
 public class AlbumInfo
 {
     public List<ActData> data;
 }

 [System.Serializable]
 public class ActData
 {
     public string id;
     public string name;
 }
 
 // ALBU$$anonymous$$ CALL //
 
 public void AlbumCallback(IGraphResult result) {

     inCallback = true;

     if (result.Error != null)
     {                                                                      
         album_data = result.RawResult;

         inCallback = false;

     }
     else
     {

         var dataDict = result.RawResult as String;

         Debug.Log(dataDict);

         AlbumInfo ANON = JsonUtility.FromJson<AlbumInfo>(dataDict);

         for(int i=0; i<ANON.data.Count; i++ ){
             
             //Debug.Log(ANON.data [i].name);

             if (ANON.data [i].name == AlbumName) {

                 AlbumID = ANON.data [i].id;

                 AlbumOnline = ANON.data [i].name;

                 Debug.Log("Das Album " + AlbumOnline + " hat die id " + AlbumID);

                 Album$$anonymous$$atch = true;

                 inCallback = false;

             }

         }

         //Debug.Log (AlbumOnline);

     }

 }


 IEnumerator UploadToPage(byte[] screenshot) {

     #if UNITY_IPHONE
     Handheld.SetActivityIndicatorStyle(UnityEngine.iOS.ActivityIndicatorStyle.WhiteLarge);
     #endif

     Handheld.StartActivityIndicator();

     FB.API (PageID + "/albums?fields=name", Http$$anonymous$$ethod.GET, AlbumCallback);

     while(inCallback)       
         yield return new WaitForSeconds(0.1f);

     var wwwForm = new WWWForm ();

     if (AlbumName != AlbumOnline || AlbumOnline == null) {

         wwwForm.AddField ("name", AlbumName);

         string url = "https" + "://graph.facebook.com/" + PageID + "/albums";
         url += "?access_token=" + PageAccessToken;

         using (UnityWebRequest www = UnityWebRequest.Post (url, wwwForm)) {
             yield return www.Send ();

             if (www.isError) {
                 Debug.Log (www.error);

                 IOSNativePopUp$$anonymous$$anager.show$$anonymous$$essage ("Failed!", "Session Reset");
                 ssCount = 0;

                 Image3Obj.SetActive (true);
                 ImagePicker.SetActive (false);

                 Handheld.StopActivityIndicator();

                 yield break;

             } else {

                 Debug.Log ("Form upload complete!");

                 Debug.Log ("Created Album " + AlbumName);
         
                 // GET ID //

                 FB.API (PageID + "/albums?fields=name", Http$$anonymous$$ethod.GET, AlbumCallback);

             }
         }


     } 

     while(inCallback)       
         yield return new WaitForSeconds(0.1f);

     if (AlbumName == AlbumOnline && Album$$anonymous$$atch == true) {

         wwwForm.AddField ("message", PostText);
         wwwForm.AddBinaryData ("image", screenshot, "Tiger" + Time.time + ".png");

         string url = "https" + "://graph.facebook.com/" + AlbumID + "/photos";
         url += "?access_token=" + PageAccessToken;

         using (UnityWebRequest www = UnityWebRequest.Post (url, wwwForm)) {
             yield return www.Send ();

             if (www.isError) {
                 Debug.Log (www.error);

                 IOSNativePopUp$$anonymous$$anager.show$$anonymous$$essage ("Failed!", "Session Reset");
                 ssCount = 0;

                 Image3Obj.SetActive (true);
                 ImagePicker.SetActive (false);

                 Handheld.StopActivityIndicator();

                 yield break;

             } else {
                 
                 Debug.Log ("Form upload complete!");

                 Debug.Log ("Uploaded Tiger" + Time.time + ".png");

                 IOSNativePopUp$$anonymous$$anager.show$$anonymous$$essage ("Success!", "Uploaded to " + PageName + " in Album \"" + AlbumName + "\"");
                 ssCount = 0;

                 Image3Obj.SetActive (true);
                 ImagePicker.SetActive (false);

                 Handheld.StopActivityIndicator();

                 yield break;
             }
         }
     }
 }
avatar image AmrmHady somejonus · Sep 16, 2017 at 11:33 AM 0
Share

Ok thanks very much, I think I get it now, I used to do this => " {PageID}/{Album-Id}/photos?access_token=xxxx " and it gave me an Error, I have an album ID already. but will also give this a try , thanks a bunch =)

update: it worked =) I should've just used the album ID like a the page ID , and add the token field.

I've also acquired the page access token from the me/accounts using Get in FB.API , and split the RawResult from " and used the string that held the access token.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

121 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Get comments on Unity using Facebook Graph API 0 Answers

how to .get scores and set scores in facebook sdk 7.7 (Scores API) 1 Answer

Unity Facebook SDK Login in using FB app rather than Safari browser 1 Answer

Share to facebook, twitter,etc. Ios Please help out 0 Answers

How to use result.ResultDictionary to fetch full json of facebook user profile who logged in my app? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges