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. CHICAN0

    CHICAN0

    Joined:
    May 5, 2011
    Posts:
    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

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @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

    Joined:
    Dec 1, 2009
    Posts:
    242
    Hi Jerotas,

    Please let me know when you got this working :)

    Roy
     
  4. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    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

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @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

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    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

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @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

    Joined:
    Dec 1, 2009
    Posts:
    242
    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

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    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

    Joined:
    Dec 1, 2009
    Posts:
    242
    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.


    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

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    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

    Joined:
    Dec 1, 2009
    Posts:
    242
    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

    Joined:
    Sep 7, 2011
    Posts:
    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

    Joined:
    Apr 18, 2012
    Posts:
    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

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @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. J_P_

    J_P_

    Joined:
    Jan 9, 2010
    Posts:
    1,027
    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

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @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. J_P_

    J_P_

    Joined:
    Jan 9, 2010
    Posts:
    1,027
    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

    Joined:
    Apr 19, 2012
    Posts:
    20
    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

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

    J_P_

    Joined:
    Jan 9, 2010
    Posts:
    1,027
    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

    Joined:
    Nov 16, 2011
    Posts:
    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

    Joined:
    Apr 19, 2012
    Posts:
    20
    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

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @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

    Joined:
    Oct 13, 2011
    Posts:
    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

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @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

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

    loock_

    Joined:
    Aug 4, 2010
    Posts:
    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

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @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_

    Joined:
    Aug 4, 2010
    Posts:
    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

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @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_

    Joined:
    Aug 4, 2010
    Posts:
    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

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @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

    Joined:
    Sep 19, 2009
    Posts:
    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

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

    zehreken

    Joined:
    Jun 29, 2009
    Posts:
    112
    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

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

    toshiya

    Joined:
    Apr 27, 2012
    Posts:
    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

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @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

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



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

    Please help :(
     
  41. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @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

    Joined:
    Jan 8, 2010
    Posts:
    167
    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

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

    koki

    Joined:
    Nov 27, 2009
    Posts:
    43
    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

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @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

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

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @koki, it is only enabled when your platform is set to iOS.
     
  48. J_P_

    J_P_

    Joined:
    Jan 9, 2010
    Posts:
    1,027
    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

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @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. J_P_

    J_P_

    Joined:
    Jan 9, 2010
    Posts:
    1,027
    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