Social Networking Plugin (Facebook and Twitter) live!

Discussion in 'iOS Development' started by prime31, Sep 19, 2010.

  1. CHICAN0

    CHICAN0

    New Member

    Joined:
    May 5, 2011
    Messages:
    4
    Hi, im trying to pass the user facebook id to a variable for future use. Im using the Prime31 Graph command, i can see it on the debuging X.code window. Now, where and how the id number is available ? Need to pass that number to a variable. Thanks in advance
  2. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,422
    @CHICAN0, please have a look at the demo scene. There is an example of exactly what you are trying to do already in there.
  3. Tapgames

    Tapgames

    Member

    Joined:
    Dec 1, 2009
    Messages:
    161
    Hi Jerotas,

    Please let me know when you got this working :)

    Roy
  4. jerotas

    jerotas

    Member

    Joined:
    Sep 4, 2011
    Messages:
    2,474
    Well, using the other token as I said earlier on this page and another WWW request, I was able to get the scores on my iPad. Note - this currently does not work using the Prime31 graph request method. To elaborate, the following does not work:
    ----------------

    public static void FacebookGetTopScores() {
    string scoreRequest = string.Format("/{0}/scores?access_token={1}", DTUtility.FACEBOOK_APP_ID, FacebookBinding.getAccessToken());

    Debug.LogError("top scores url: " + scoreRequest);
    Facebook.instance.graphRequest(scoreRequest, HTTPVerb.GET, GetTopScoresCompleted);
    }
    -----------------

    That nets me an "invalid application ID" error when it calls back. The following does work though:
    -----------------

    public static IEnumerator GetFriendScores() {
    string scoreRequest = string.Format("https://graph.facebook.com/{0}/scores?access_token={1}", DTUtility.FACEBOOK_APP_ID, FacebookBinding.getAccessToken());

    Debug.LogError("friend scores URL: " + scoreRequest);

    WWW fbRequest = new WWW(scoreRequest);

    // Wait for download to complete
    yield return fbRequest;

    string scoresJSON = fbRequest.text;
    Debug.Log("friend scores: " + scoresJSON);

    return true;
    }
    --------------------------
    So apparently the graph API must be somehow not keeping the URL intact. These URL's should be identical. Anyway I can continue on my work now, I hope this is of some help to someone. Please figure out what's going on with this Prime31. The only drawback to my method is that I have a large string of JSON to parse now instead of a HashTable. Oh well, I can work it. Anyone know a quick way to convert JSON into something more workable like a DataTable or whatever?
  5. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,422
    @jerotas, you are adding the access token twice in your examples. The plugin automatically appends the access_token parameter for all requests.
  6. jerotas

    jerotas

    Member

    Joined:
    Sep 4, 2011
    Messages:
    2,474
    Indeed, that was the problem Prime, thanks! Now I can use the normal Graph call from the plugin. It's kind of a pain to loop through the Hashtable's ArrayList's Hashtable to get the scores, but it works.
  7. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,422
    @jerotas, it is slightly advanced but our latest video tutorial shows some of the hidden features that come with the plugin. Note that we do not support them do to their advanced, undocumented nature.

  8. Tapgames

    Tapgames

    Member

    Joined:
    Dec 1, 2009
    Messages:
    161
    Hi Jerotas,

    I thought it was for posting the score to facebook. Do you have that working too?

    Thanks in advance,
    Roy
  9. jerotas

    jerotas

    Member

    Joined:
    Sep 4, 2011
    Messages:
    2,474
    Yes I do. Let me know what you're doing now and I'll try to see what the diff is in my code and let you know.
  10. Tapgames

    Tapgames

    Member

    Joined:
    Dec 1, 2009
    Messages:
    161
    Hi Jerotas,

    Thanks man!

    I setup an open graph in facebook like this. I have no clue if I have to do this but I did.
    [​IMG]

    And used primes demo and changed his app id and secret.
    But I dont see the scores apair on my facebook.

    Thats all,
    Roy
  11. jerotas

    jerotas

    Member

    Joined:
    Sep 4, 2011
    Messages:
    2,474
    Yeah, you don't have to set up anything on graph. Score exists automatically if it's a "game" type. I don't see scores on my Facebook either, I'm not sure how to get those to show up there. But I do have scores when I query the graph API for scores of my app. Have you tried that?

    Anyone know how to get the scores to actually show up on Facebook?
  12. Tapgames

    Tapgames

    Member

    Joined:
    Dec 1, 2009
    Messages:
    161
    When I testing it with the demo scene from prime I can submit score but it doest show up on facebook and when I press getscore I see the correct score in xcode console showup so thats working.

    I only want users to post there highscore on there facebook account for other people to see. :)

    Posting from unity to facebook was easy. but now the scores.
  13. EricD

    EricD

    New Member

    Joined:
    Sep 7, 2011
    Messages:
    128
    Hi,

    I'm trying to use the facebook plugin on iOS. But I can't post a screenshot. I use postimage, but I don't get the image or it doesn't post the image. Even in the example scene.
    Last edited: Apr 18, 2012
  14. L1F3Stream

    L1F3Stream

    New Member

    Joined:
    Apr 18, 2012
    Messages:
    1
    Hi prime31,

    I'm currently using FacebookBinding.showDialog and FacebookBinding.showPostMessageDialogWithOptions to popup a dialog after certain events. At both actions I enter the 'name' property to represent the attached link.

    The name property is visible at my Facebook Wall as link title, but it isn't visible at the dialog popup within the app. The only things visible within the popup which are adjustable are the 'caption', 'description' and 'image' fields. Is there any possibility to display the name within the dialog popup?

    Thanks!
    Last edited: Apr 18, 2012
  15. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,422
    @ericd, what error are you seeing returned when you call the method to post the image?


    @l1f3, the dialogs run off of Facebooks servers and are not customizable.
  16. JTown.

    JTown.

    Member

    Joined:
    Jan 9, 2010
    Messages:
    852
    Before the latest update, I could get a friend list and ask for additional fields. Is that not possible anymore?

    Code (csharp):
    1. Facebook.instance.graphRequest("me/friends?fields=id,name,birthday", HTTPVerb.GET, ReceiveFriendBirthdays);
    error: message: An active access token must be used to query information about the current user.
    type: OAuthException
    code: 2500

    But this works:
    Code (csharp):
    1. Facebook.instance.graphRequest("me/friends", HTTPVerb.GET, ReceiveFriendBirthdays);
    In the previous version, something like this worked:
    Code (csharp):
    1. FacebookBinding.graphRequest("/me/friends?fields=id,name,birthday", "GET", Hash);
    Any ideas? It was nice being able to get friends and additional info in one request.. I'd rather not go through every friend to find their birthday with a separate request. Those fields still work if I use the fb graph api explorer https://developers.facebook.com/tools/explorer

    edit: I tried using my own user id instead of 'me' and got interesting results. It works fine on the graph api explorer, but I get an error like this if I do it in the app:

    error: message: (#100) Unknown fields: birthday?access_token=[myaccesstoken]
    type: OAuthException
    code: 100
    Last edited: Apr 18, 2012
  17. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,422
    @Jtown, you should be able to pass in the "fields" parameter with the value "id,name,birthday" as a standard parameter of type Dictionary<string, object> to the "me/friends" path. Give that a go and see if it does the trick.
  18. JTown.

    JTown.

    Member

    Joined:
    Jan 9, 2010
    Messages:
    852
    Worked like a charm. Thanks!

    edit: I love the new completion handlers, btw

    edit2: This has nothing to do with the plugin, but I thought it was interesting: I noticed for one of my friends, the graph request doesn't get a birthday for her -- but if I go to her page normally, her full birthday is right there, so it's not like she doesn't have it shared.
    Last edited: Apr 18, 2012
  19. priznut

    priznut

    New Member

    Joined:
    Apr 19, 2012
    Messages:
    15
    I really wish it was documented that using postscore does not actually post them on Facebook. Very disappointed because I thought I was doing something wrong.

    I tried various methods, but looks like mobile iOS apps that call post score are not posted on Facebook. Posting to walls is simple enough. Hopefully it is something Facebook is working on and have plans to amend.
  20. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,422
    @JTown, I believe there is a permission required to get a users birthday.
  21. JTown.

    JTown.

    Member

    Joined:
    Jan 9, 2010
    Messages:
    852
    Oh there is. And I get it for most of my friends. Just happened to notice one that I wasn't getting a birthday for despite them listing it if I went to their page. My app now sets up local notifications for your friend's birthdays :)
    Last edited: Apr 19, 2012
  22. Denifia

    Denifia

    New Member

    Joined:
    Nov 16, 2011
    Messages:
    32
    I am about to buy and integrate this plugin to my next game. Just wanted to say thanks for making it - it looks great :D
  23. priznut

    priznut

    New Member

    Joined:
    Apr 19, 2012
    Messages:
    15
    So just have a minor issue. I have Facebook and Twitter working well for iOS. I also have Facebook working well with Android.

    Need help with the Twitter side of things. So far I have the Twitter logging working successfully, as well as posts, but it's not firing the even which I assume is mean for posts:

    Code (csharp):
    1.     // Fired when a request succeeds.  The returned object will be either an ArrayList or a Hashtable depending on the request
    2.     public static event Action<object> requestSucceededEvent;
    3.    
    4.     // Fired when a request fails with the error message
    5.     public static event Action<string> requestFailedEvent;
    These events are not firing, but tweets are being posted successfully. Here is my bit of code:

    Code (csharp):
    1.     TwitterAndroidManager.requestFailedEvent -= T_Postfailed;
    2.     TwitterAndroidManager.requestSucceededEvent -= T_PostAndroid;
    3.  

    Else in the same script:

    Code (csharp):
    1. function T_PostAndroid( response:Object )
    2. {
    3.     T_Post( );
    4. }
    5.  
    6. function F_Postfailed( error:String ) {
    7.     OutputText.Text = "Error";
    8.     OutputDetailText.Text = error;
    9.     SocialDetailTextColor( );
    10.     Invoke( "SocialFadeDetailTextOut", 5.0 );
    11.     Invoke( "SocialFadeTextOut", 5.0 );
    12. }
    13.  

    Anything I'm missing or using incorrectly? Again it is posting on twitter but just not firing this event.
  24. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,422
    @priznut, the requestSucceeded/Failed event are for the performRequest method. The twitterPostFailed/Succeeded events are for a standard status update post. You can always stick the *EventListener prefab in your scene and watch the logs. It will dump every event to the console and can be quite informative.
  25. iRetrograde

    iRetrograde

    New Member

    Joined:
    Oct 13, 2011
    Messages:
    93
    Hey Prime,

    Thanks again for all the help and I got another question.

    My user posts are appearing into their feeds just like expected, however they always come in as private.

    Do I have to use the FacebookAndroid.showPostMessageDialogWithOptions functionality or should I move away and do my own POST requests to their feeds?

    I was having issues with the friends request dialog as well in the past, have tried to re-create my account and re-wire everything and still having issues. I'm not sure if you had any leads back from FB but it's a bit disheartening to potentially see users posting to their feeds without it being an effect method of sharing with their friends. I've tried several times uninstalling the app from the accounts and doing all sorts of things to make sure that posts and requests seem to be coming in properly.

    If you received any useful information back from them, please let me know. I'm still in a bit of limbo with why these posts are behaving in this manner.

    Cheers.
  26. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,422
    @iretro, you will need to consult Facebooks docs to get information that detailed. Their system is absolutely massive so we do not know every minute detail with regard to their permission system
  27. Breakmachine

    Breakmachine

    Member

    Joined:
    Sep 19, 2009
    Messages:
    39
    did you find out how to decode Ѐ ?
  28. loock_

    loock_

    New Member

    Joined:
    Aug 4, 2010
    Messages:
    18
    Hello Prime31,

    I'm trying to port the functionality of my app over Android version and I faced some issues - when trying to call a simple Graph request I get an error "java.io.FileNotFoundException: https://graph.facebook.com/me?fields=id%2cname"

    Call:
    Handler:
    Parameter "key" returns the above error and the parameter "value" is null. Oh, and even the simpler call with path "me" but without any fields returns the same error.

    Where can be the problem? Please help!
  29. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,422
    @loook, I believe you have something else going on there. Unitys WWW class appears to be interpreting the Graph URL as a file. Do you have the force Internet permission set?
  30. loock_

    loock_

    New Member

    Joined:
    Aug 4, 2010
    Messages:
    18
    @Prime: Yes, I switched the Internet Access option in Unity Player settings from Auto to Require but this didn't change anything.. And I do have active wi-fi connection while testing.
  31. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,422
    @looock, you will need to open a bug report with Unity for that one. All http* urls should never go anywhere near the file system.
  32. loock_

    loock_

    New Member

    Joined:
    Aug 4, 2010
    Messages:
    18
    @Prime: Could you possible provide me (via PM) a package with the previous version of the Android plugin (before those major changes in API about 2 weeks ago)? Maybe the older one will gonna work for me.
  33. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,422
    @looock, we do not have the previous version available anymore. If a simple WWW call is not working for you neither the old nor new version will work. You will definitely want to open a bug report with Unity as soon as possible.
  34. Breakmachine

    Breakmachine

    Member

    Joined:
    Sep 19, 2009
    Messages:
    39
    @Prime: Do you by any chance know how to decode the Unicode Character Codes in the reply from graphRequest? For example I get email in this format: mail@mail.com.

    /Sven
  35. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,422
    @break, you can find unicode conversion classes in the System.Globalization namespace. If you Google it you will find many examples.
  36. zehreken

    zehreken

    Member

    Joined:
    Jun 29, 2009
    Messages:
    54
    Hi,
    Is it possible to get the apps(in this case, my app) which current user's friends are using. I want to pair the user with his/her friends on facebook.
  37. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,422
    @zehreken, you will need to check Facebooks Graph API docs to see what is possible. There are hundreds of methods available.
  38. toshiya

    toshiya

    New Member

    Joined:
    Apr 27, 2012
    Messages:
    8
    Hi
    I bought Social Networking Plugin for iOS and Andoroid. I import it two for one project.

    For Android, it's no problems. I was able to log in to Facebook and get access token.

    but for iOS, When I logged in same AppId for init() and login(), it became the error.
    Safari says "Invalid URL" (url's http://m.facebook.com/dialog/permissions.request)

    Is any setting necessary?

    (Sorry.. I can't write English well)
  39. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,422
    @toshiya, make sure you properly setup your app on the Facebook developer portal including setting up your bundle ID. You then must make sure your bundle ID is the same in Xcode and that Xcode is using the provisioning profile with the same bundle ID.
  40. shadowfork

    shadowfork

    Member

    Joined:
    Jan 8, 2010
    Messages:
    153
    So I updated my project with Prime's latest release but this started coming out of my project:

    [​IMG]

    It won't go past the default start up image.

    Please help :(
  41. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,422
    @shadow, that looks like an issue with Unity startup. Our plugin code doesn't run any code unless you explicitly call a method and that error looks like the app didnt even launch. Do a build followed by replace to get a fresh Xcode project.
  42. shadowfork

    shadowfork

    Member

    Joined:
    Jan 8, 2010
    Messages:
    153
    Thanks! Cleaned up the initialize scene and replaced with the new prefabs and it worked :)

    Also, on another note, just to clear things up, you've consolidated the calls between iOS and Android, but they're still two different asset files to install, correct?
  43. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,422
    @shadowfork, that is correct. They are still totally different plugins just that they now share the same API.
  44. koki

    koki

    Member

    Joined:
    Nov 27, 2009
    Messages:
    37
    Hi prime31, i'm using the Android plugin and it works fine, but i'm facing a problem when posting on facebook using iOS plugin. I can enter my login data and it asks me if i want to grant access to my app, i hit the "okay" button on the top of the page but nothing happens. What am i missing? Thanks!
  45. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,422
    @koki, retread the documentation paying special attention to the part about URL schemes. Double and triple check the values you enter on the Facebook website and your URL scheme to make sure everything matches.
  46. koki

    koki

    Member

    Joined:
    Nov 27, 2009
    Messages:
    37
    @prime31, i can't open the "Info.plist additions" cause its disabled in the menu. How do i enable it?
  47. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,422
    @koki, it is only enabled when your platform is set to iOS.
  48. JTown.

    JTown.

    Member

    Joined:
    Jan 9, 2010
    Messages:
    852
    It's giving html hexadecimal codes for special characters like è (when I grab names) -- is there a way to convert those to UTF? System.Web seems unavailable to Unity, so I can't do HttpUtility.HtmlDecode...

    edit: Is there a place I can convert it in objc before Unity gets it? This is for Graph API request results.
    Last edited: Apr 29, 2012
  49. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,422
    @jtown, you would have to modify the Facebook SDK to catch it on the Obj-C side. Graph requests no longer even make it to Obj-C. They are all handled right in Unity. Like I mentioned a few posts up, you can find unicode conversion classes in the System.Globalization namespace. If you Google it you will find many examples.
  50. JTown.

    JTown.

    Member

    Joined:
    Jan 9, 2010
    Messages:
    852
    Thank god haha. I kept getting pointed in the HtmlDecode direction, so I didn't know Globalization could do it.

    Code (csharp):
    1. hexString = hexString.Substring(3, 4);//remove and semicolon
    2.                     int num = int.Parse(hexString, System.Globalization.NumberStyles.AllowHexSpecifier);
    3.                     char cnum = (char)num;
    4.                     separated[i] = cnum;
    Last edited: Apr 29, 2012