Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Closed] Social Networking Plugin (Facebook and Twitter) live!

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

  1. iRetrograde

    iRetrograde

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

    I went to go over my issues today (got a twitter issue fixed) and after going over FB documentation for the apprequests stuff and I just wanted to follow up with a few questions:

    One, below is my code that I'm using to launch the apprequest dialog to players. Do I have to enter any more to it? Like an authorization parameter or something else?

    Code (csharp):
    1.  
    2. var parameters = new Dictionary<string,string>();
    3. parameters.Add( "message", "Forget those old word games, come play something refreshing!" );
    4. FacebookAndroid.showDialog( "apprequests", parameters );
    5.  
    Now, another thing that I noticed was that a few things came out of looking through FB documentation.

    In the dialogue request documentation (https://developers.facebook.com/docs/reference/dialogs/requests/)

    1. "Requests are only available for Desktop Canvas apps and not websites. Accepting a request will direct the user to the Canvas Page URL of the app that sent the Request."

    I'm going to contact FB again for all of this, and see if this is still possible, but it seems like the limitation might be from our end, and the fact that we're generating a request from an android native app instead of a canvas app. Does this make any sense? Should I still be able to launch requests?

    Again, no response yet from the FB side of things so I'm trying to keep digging a bit more since putting this in the game is something desirable.

    Are you doing anything overly different than what I'm trying to do to send out those app requests from within your game?

    Cheers!
     
  2. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @iretro, that is all that is required for apprequests. You should be able to see quite obviously that it is possible by the actual dialog that Facebook displays. Further evidence is that it returns proper request IDs in the callback event.
     
  3. doppe

    doppe

    Joined:
    Apr 10, 2012
    Posts:
    6
    Hello, I just want to know how can I get facebook ID and user name.
    Help me please!
     
  4. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @doppe, the "me" Graph API path will get you that info.
     
  5. iRetrograde

    iRetrograde

    Joined:
    Oct 13, 2011
    Posts:
    93
    @Prime

    You know, even though I'm getting the right info coming through the event handlers, I'm just not familiar with how FB and other things work yet to not be double and triple checking things.

    Thanks for your time Prime, I'm gonna go annoy FB now...
     
  6. doppe

    doppe

    Joined:
    Apr 10, 2012
    Posts:
    6
    Thank you for your quick reply but unfortunately I don't understand what you mean.
    Please tell me the right code should I put and the right position of the source then I could try them!
     
  7. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @doppe, see the demo scene for example code. The "me" request is included in the demo scene. Also be sure to visit the documentation page for all the exposed methods.
     
  8. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
  9. doppe

    doppe

    Joined:
    Apr 10, 2012
    Posts:
    6

    Where can I find the demo scene? Are there many demos? Which one should I check?
    Also want to know Which part of documentation is right for me.
    Thank you!
     
  10. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @doppe, the demo scene is in the testSupport folder. The entirety of the documentation is relevant and you absolutely need to read it if you want Facebook or Twitter in your app.
     
  11. bbvrdev

    bbvrdev

    Joined:
    Aug 11, 2009
    Posts:
    221
    Clearly I'm doing something wrong... Prime, could you give me a quick step-by-step for the following?
    Which methods do I need to call every time the app is launched AFTER the user has approved it on FB?
    Init(), and ... ?

    I obviously would prefer not to load the FB app or login page each time, if that's possible.
    Thanks again for your help.
     
  12. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @sand, init should be called at app launch. It does nothing but set your credentials and fetch the access token if the user is already logged in. That is all you need.
     
  13. bbvrdev

    bbvrdev

    Joined:
    Aug 11, 2009
    Posts:
    221
    Thanks Prime, so the issue with my not being able to post on subsequent launches after the first likely has to do with receiving a null access token? I am indeed calling init every time.
     
  14. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @sand, are you checking before posting with isSessionValid?
     
  15. bbvrdev

    bbvrdev

    Joined:
    Aug 11, 2009
    Posts:
    221
    Not at the moment, because I reverted to the old version of the plugin. Couldn't get the other one to work, and I unfortunately I can't wait.
    What is the old-school equivalent? Should I be checking this every time?
     
  16. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @sand, the flow should always be to call init at app launch. When ready to use Facebook check isSessionValid and if it isn't login before calling any other methods.
     
  17. bbvrdev

    bbvrdev

    Joined:
    Aug 11, 2009
    Posts:
    221
    Is isLoggedIn() the older version? If so, I was doing that. Also, do I need to have an iframe canvas set up in FB as well as the app ID? I keep getting a 404 over there. Something has obviously changed.
     
  18. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @sand, you do not need anything other than a standard iOS native app setup in Facebook. Anything else is optional.
     
  19. bbvrdev

    bbvrdev

    Joined:
    Aug 11, 2009
    Posts:
    221
    Hi Prime, I've got it loading the FB app to login, but once logged in, it automatically returned to a build of the test scene I had on the device. Now it won't return to my actual game!

    Thoughts?
     
  20. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @sand, that is the expected behavior if you have multiple apps installed on your device with the same URL scheme. Either delete the old apps or use a URL scheme suffix for each app.
     
  21. bbvrdev

    bbvrdev

    Joined:
    Aug 11, 2009
    Posts:
    221
    Should I be putting my URL scheme "fb12345" id in the URL scheme suffix area in the FB app setup page?
     
  22. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @sand, have a look through the tutorial on the Facebook developer portal to see if a URL scheme suffix is right for your app.
     
  23. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Okay, I believe that I've successfully posted a score to Facebook. Now is there anywhere on the web I can go to look at scores posted? By the way, I replaced the broken new method with my old WWW code to get this far:

    This does not work - returns only empty string.
    ---------------
    public static void GetAppAccessToken() {
    Debug.Log("getting app access token!");

    Facebook.instance.getAppAccessToken( FACEBOOK_APP_ID, FACEBOOK_APP_SECRET, token =>
    {
    Debug.Log("received app access token: " + token);
    FacebookAppAccessId = token;
    });
    }
    ---------------

    This works:
    -----------------
    public static IEnumerator GetAppAccessToken() {
    //Debug.Log("asking FB for App AccessToken");
    string url = string.Format("https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id={0}&client_secret={1}",
    FACEBOOK_APP_ID,
    FACEBOOK_APP_SECRET);

    WWW fbRequest = new WWW(url);

    // Wait for download to complete
    yield return fbRequest;

    string accessToken = fbRequest.text;
    //Debug.Log("got token: " + accessToken);
    accessToken = accessToken.Substring(accessToken.IndexOf("=") + 1);
    //Debug.Log("trimmed token: " + accessToken);

    FacebookAppAccessId = accessToken;

    return true;
    }
     
  24. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    I also wanted to know if the App Access Token is something that ever changes? Or can I just get that ID once and then hard-code it into my app?
     
  25. doppe

    doppe

    Joined:
    Apr 10, 2012
    Posts:
    6
    prime, I already checked the demo and tried some, but I can't get facebook ID yet.
    I mean, Facebook Platform has id 19292868552.
    I just want to get this '19292868552' number form each user.
    Is there any example for this case?
     
  26. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @jerotas, you will have to check with Facebook to find out the lifetime of an app access token.


    @doppe, press the "Graph Request (me)" button in the demo scene and watch the Xcode logs. If that doesn't get what you need consult Facebooks documentation and see which Graph API call does.
     
  27. doppe

    doppe

    Joined:
    Apr 10, 2012
    Posts:
    6
    prime, I use Andoroid. Please tell me about Android.
    I bought your unity Android Social Networking Plugin and I want to know about it.
    In this case, which part should I check instead of Xcode?
     
  28. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @doppe, this is the iOS forum and you are referring to an Android plugin. Android plugins have absolutely nothing to do with iOS or Xcode. If you have an Android specific question about the plugin please post it in the Android forum topic. Please refer to Facebook's Graph API docs which contain the parameters and return values of every available Graph API method and our docs for how to call a graphRequest.
     
  29. doppe

    doppe

    Joined:
    Apr 10, 2012
    Posts:
    6
    Thank you prime, I got facebook ID and name anyway.
    Thank you very much!
     
    Last edited: Apr 11, 2012
  30. bbvrdev

    bbvrdev

    Joined:
    Aug 11, 2009
    Posts:
    221
    @jerotas I am trying your WWW method posted above, but still I get a blank string back from the www. I'm wondering if either you or Prime have any ideas as to why this might be happening?

    EDIT: I got the access token working using your method. Still I get a blank error message when trying to log in however. Thanks a million for posting this, Jerotas!

    EDIT 2: While I can get the access token using the Jerotas method, I can't seem to figure out how to pass it in so that I can log in using it. Anyone?
     
    Last edited: Apr 11, 2012
  31. bbvrdev

    bbvrdev

    Joined:
    Aug 11, 2009
    Posts:
    221
    @Jerotas, now that you've gotten the access token, did you have any luck passing it in so that the app can post a message?

    @Prime, any idea why I might be receiving a blank error message when trying to login?

    EDIT: Never mind, I got it!! The test scene needed to have the same bundle ID as the main app (duh!)
     
    Last edited: Apr 12, 2012
  32. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    A new version just went live that has has methods to post a score and retrieve all the scores for a player. To stay up to date don't forget to checkout the release notes page or if you prefer RSS add this link to your favorite RSS reader.
     
  33. bbvrdev

    bbvrdev

    Joined:
    Aug 11, 2009
    Posts:
    221
    Is there a method to get and store the extended access token? According to the FB docs, the offline_access is deprecated.
     
  34. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @sand, extendAccessToken and getAccessToken
     
  35. bbvrdev

    bbvrdev

    Joined:
    Aug 11, 2009
    Posts:
    221
    Thanks Prime! And does that store the token for future use?
     
  36. jpatinop

    jpatinop

    Joined:
    Mar 30, 2012
    Posts:
    7
    Hello.. nice plugin, can i take a screenshot and post in the Facebook wall or on twitter?
     
  37. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @jpatinop, you can post screenshots to both Twitter and Facebook with the plugin.
     
  38. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Awesome, the post score method appears to work. Also, in this newest version the getAppAccessToken method does work for me. I don't need my WWW code anymore :)

    The getScores method is of no use to me since it only gets the current player's scores - but I am trying to do something similar. I want to get the top scores for the application among the current player and their Facebook friends. I've been having no luck. I've been using this code:

    ----------------------------------

    string scoreRequest = string.Format("/{0}/scores?access_token={1}", FACEBOOK_APP_ID, FacebookAppAccessId);
    Facebook.instance.graphRequest(scoreRequest, HTTPVerb.GET, GetTopScoresCompleted);

    ---------------------------------

    When the callback comes, it says: "error = bad URL". However, if I paste the URL into my browser - prefixed with https://graph.facebook.com - the browser says: "message": "A user access token is required to request this resource."

    How do I get past this? I don't even know if my code is the right way to retrieve scores or not...

    Thanks guys, we're halfway there!
     
  39. Tapgames

    Tapgames

    Joined:
    Dec 1, 2009
    Posts:
    242
    I have manage to get stuff on my facebook but not scores.

    I only want that users with facebook playing my game can submit there scores "just a simple integer" to there timeline.

    like this:


    I used the exemple projects to test when I postScore it is succesful but I don't see that on my facebook.
    When I click "Get Scores" I see the correct score in de command line of xcode.

    Someone that have this working?
     
  40. Everance

    Everance

    Joined:
    Dec 2, 2011
    Posts:
    3
    Hi Prime31,
    I'm very interested in having Google+ plugin for Unity3d. Are you going to support Google+ integration?

    Thanks in advance,
    Alexander
     
  41. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @everance, I already answered your email.
     
  42. DavidButtress

    DavidButtress

    Joined:
    Aug 30, 2011
    Posts:
    32
    Hey, I've just bought/installed the plugin for iOS. Is there a reason for having lots of the code #if UNITY_IPHONE defined out? It causes masses of compiler errors in the editor. I've just removed all the #ifs out and it seems to work ok, but I just wanted to check why it was set up like this?
     
  43. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @teacup, the precompiler directives can safely be removed. They ate there for users working on both iOS and Android.
     
  44. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    How can I get assistance on this? Can I open a ticket with you guys, Prime31, or something? I emailed you on your website just now. Not sure if that was the right avenue.
     
  45. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Figured it out guys!! To get the scores of you and all your friends, you need to pass FacebookBinding.getAccessToken() as the "access_token". Rock on!
     
  46. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    I spoke too soon....I got it working in the BROWSER with the same URL, saw all the scores there. But when I call it from Facebook.instance.graphRequest, it returns "Error validating application. Invalid application ID."

    I noticed that this same message is returned in the browser if the super-long access_token has a character chopped off. I'm not doing that...any idea how to troubleshoot this Prime?
     
  47. swiv

    swiv

    Joined:
    Mar 22, 2009
    Posts:
    30
    Dear Prime,

    Twitter have now granted me xAuth access, so I am changing my game to ask for Twitter credentials via showPromptWithTwoFields in your Etc plugin. Previously it was using showOauthLogiDialog.

    This all works fine but there is a problem with the display. If you rotate the iPad whilst the showPromptWithTwoFields is on screen, for every rotate the background blue rectangle of the prompt shrinks in its vertical size ever so slightly (id say about 20 pixels). If you keep doing this it disappears altogether. It isn't just a display issue though as it seems that as soon as the background dimensions of the prompt makes the OK and Cancel buttons reside outside of the prompt box, the buttons no longer work. (This takes two rotates for me). To the player they are then stuck with the prompt on screen and can't get out of it.

    Is there anything I can do to fix this?

    Cheers for any help.
     
    Last edited: Apr 17, 2012
  48. swiv

    swiv

    Joined:
    Mar 22, 2009
    Posts:
    30

    It seems that in P31AlertView.m you reduce the height by 22 pixels if contractHeight is set (each time it rotates). I've taken than out and got it working. Thanks
     
  49. DavidButtress

    DavidButtress

    Joined:
    Aug 30, 2011
    Posts:
    32
    Got the plugin in working nicely now, thanks a lot. Got one question though, if the user isn't using the tweetsheet is there a dialog available for the user to see/edit a tweet before it's sent (similar to the FacebookBinding.showPostMessageDialogWithOptions) I couldn't see anything in there already, but I just wanted to check before I create something from scratch as it seems like a common requirement.

    Ta
     
  50. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @teacup, Twitter doesn't have a dialog system like Facebook does so you can make one in the style of your game to grab the user's post.