Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

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

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

  1. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @Luck, Facebook won't let you create your own login dialog for security reasons. Their authentication process first tries native iOS (as setup in the Settings.app), then it will try the Facebook.app if it is installed. It will only then fall back to a webview.
     
  2. LuckSound

    LuckSound

    Joined:
    Oct 5, 2013
    Posts:
    4
    @prime Ok. But sometimes in your test scene i get windowed login (it will not leave from game). And sometimes no. Settings didn't changed. Why I can take that results?
     
  3. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @luck, if you want to force Facebook to use a specific authentication style you can do so with the setSessionLoginBehavior method. Otherwise their SDK chooses how authentication happens.
     
  4. LuckSound

    LuckSound

    Joined:
    Oct 5, 2013
    Posts:
    4
    @prime i try it later and write about results here.
     
  5. LuckSound

    LuckSound

    Joined:
    Oct 5, 2013
    Posts:
    4
    @prime Yes. it works good. Thank you so much
     
  6. begray

    begray

    Joined:
    May 9, 2013
    Posts:
    6
    Hi,

    Is it possible to implement twitter reverse auth (https://dev.twitter.com/docs/ios/using-reverse-auth) using Prime31 SocialNetworking plugin?
    Did anyone manage to make it work? I'm stuck at step two - twitter returns 'Client is not permitted to perform this action' for attempt to get new access token.

    What I'm trying to implement is: link user in-game account with twitter login using proper server side validation (that's what access token is required for).
    I didn't find any other way to retrieve twitter access token from plugin. Did I miss something? Or there is another way to implement such feature?

    Thanks
     
  7. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @begray, if all you are after is the token you can fetch it directly from PlayerPrefs with the key "kLoggedInUser" anytime after logging a user in. Note that it is in raw form so you will have to parse it yourself.
     
  8. begray

    begray

    Joined:
    May 9, 2013
    Posts:
    6
    Thanks, that's exactly what I needed. (.. and no twitter reverse auth is necessary)

    Don't you think, that docs at http://prime31.com/docs#iosSocial should mention this somehow?
    There is API method to get Facebook token after all, but it's not clear how to achieve that for twitter.
     
  9. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @begray, believe it or not, you are the first person to ever ask for a Twitter access token. Twitter is kind of immediate vs Facebook which has long-standing data so most folks use it only to post so getting the access token isn't required.
     
  10. zhbjvd

    zhbjvd

    Joined:
    Dec 17, 2013
    Posts:
    12
    Hi, i want user to sign into facbeook from inside the app. Is there some way to do this ?
     
  11. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @zhbjvd, I wouldn't suggest it but you can use the setSessionLoginBehavior to force any login behavior that you want. Do be aware that by forcing your users to login in your app they cannot use the much more convenient Facebook.app auth process.
     
  12. adocracy

    adocracy

    Joined:
    Aug 13, 2013
    Posts:
    6
    True - but Unity is being used for way more than games nowadays...
     
  13. kromenak

    kromenak

    Joined:
    Feb 9, 2011
    Posts:
    266
    Hey Prime,

    A couple people mentioned this error a few pages ago without any solution found, but I'm also getting this very unfortunate error:

    More specifically, this issue suddenly arose after upgrading to Unity 4.3 (may be coincidental) and only occurs when logging in via the Facebook app or the web browser - using the iOS integrated FB sign-in works fine. I've checked the various info.plist additions to ensure that the bundleID and app name were correct, but the issue is persisting. During the login process, Facebook appears correctly, confirms the permissions, and switches back to the app - but then fails.

    The version of the game on the app store, which was built with Unity 4.2, authenticates fine, so I don't think our FB app settings are the cause either.

    Any ideas or leads as to why something like this would occur? The plugin code shows a failure with no error message, but I haven't found any information on why that particular scenario would occur.
     
  14. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @kromenak, that particular error is almost always due to Info.plist or bundle ID not matching exactly what was entered into the Facebook portal. Double and triple check the values and try deleting the app from your devices completely before building.
     
  15. kromenak

    kromenak

    Joined:
    Feb 9, 2011
    Posts:
    266
    Yo Prime, I finally discovered that the issue was another plugin we're recently added that had extended UnityAppController and overrode application:eek:penURL without calling the base class's implementation. It seems Facebook relies on the base implementation when switching between the FB app or Safari, so the call failed when returning back to our app.

    Anyway, kind of an edge case, but thought I'd mention in case others find themselves in a similar situation.
     
  16. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    418
    I'm using the Mac Social Networking plugin in my project but when I try to do a Win8 store build I get this error:

    Assets\Plugins\SocialNetworkingCommon\Facebook\Facebook.cs(58,34): error CS1061: 'System.Type' does not contain a definition for 'Assembly' and no extension method 'Assembly' accepting a first argument of type 'System.Type' could be found (are you missing a using directive or an assembly reference?)

    Instead of deleting the plugin from the project is there anything I can do? I saw in that script a note about windows store/phone apps and that it shouldn't cause any issues but I'm still getting the error. And yes, I do understand that this version of the plugin is just for Mac, but I would rather not delete it from my project folder if possible for my win 8 store build.

    Thanks!
     
  17. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
  18. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,245
    I created an app as a developer on facebook and put the appID in the 2 places in the tutorial video, however when I run the tutorial scene on the ipad the login button doesn't bring up the dialog (I call the init first) and the session is always false because I can't login.

    What am I missing?
     
  19. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,245
    Also how can I send an image on a twitter post from the project instead of making a screenshot?
     
  20. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @theraider, how about posting some logs so I have some information to work with. The Twitter image post methods doesn't care what the original source of the image is. It takes a path to a file as a parameter so just pass in a path to whichever file you want to post.
     
  21. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,245
    I looked more deeply and realised this "2014-01-19 10:45:10.234 TimeToMeasure[17573:60b] ERROR: You have not setup your Facebook app ID in the Info.plist file. Not having it in the Info.plist will cause your application to crash so the plugin is disabling itself." is saying the info.plist file isn't set up, but I put in the setting and closed xcode and did a plain build.



    On the twitter image, how do you find the path of a file in your project?
     
  22. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,245
    Well I fixed the fb issue :) I had the ID in the wrong place. However I have to login and then authorise in order to post. Is there anyway to join them together to become one action? Now I have authorised how do I reset the facebook permissions so I can try again?

    On twitter I tried using "var pathToImage = Application.dataPath + "/" + "Interfaces" + "/" + "DarkBlue.png";" and that doesn't appear to work.
     
  23. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @theraider, Facebook made the change to require read and write permissions to be separated over 18 months ago. There is no way around it. Always check your image paths with standard Mono/.NET methods such as File.Exists
     
  24. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,245
    Thanks for the reply.

    "Always check your image paths with standard Mono/.NET methods such as File.Exists" that is something I wouldn't know how to do :(. I thought it would be simple to find an image that is already in the project.
     
  25. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,245
    on more questions why does
    Code (csharp):
    1.  
    2. function PostTwitterScreenShot()
    3. {
    4.    
    5.    
    6.     Application.CaptureScreenshot("shot.png");
    7.     Debug.Log("Saving Shot " + Application.persistentDataPath + "/" + "shot.png");
    8.     yield;
    9.    
    10.     var pathToImage = Application.persistentDataPath + "/" + "shot.png";
    11.     TwitterBinding.postStatusUpdate( "This is an Image test: " + Time.deltaTime, pathToImage);
    12.    
    13.     Debug.Log("Posting");
    14. }
    15.  
    not work, but

    Code (csharp):
    1.  
    2. function PostTwitterScreenShot()
    3. {
    4.    
    5.    
    6.     Application.CaptureScreenshot("shot.png");
    7.     Debug.Log("Saving Shot " + Application.persistentDataPath + "/" + "shot.png");
    8.     yield;
    9.    
    10.     var pathToImage = Application.persistentDataPath + "/" + "shot.png";
    11.    
    12.     TwitterBinding.showTweetComposer( "I'm posting this from Unity with a fancy image: " + Time.deltaTime, pathToImage );
    13.  
    14.     Debug.Log("Posting");
    15. }
    16.  
    I get no error message or anything like that in the log :/

    The first one works if I take the screenshot in the start() like the demo but as soon as I try to overwrite the image it doesn't work.
     
  26. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,245
    One more thing do you have a demo scene GUI in unityscript? While converting the twitter one was easy, I am unsure how to convert the facebook one.
     
  27. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @theraider, your first example assumes taking a screenshot takes exactly no time which is quite untrue. In fact your second makes that same assumption. CaptureScreenshot can take over a second to complete so you can't do anything with the screenshot until it is written to disk.

    For a variety of reasons we do not provide UnityScript examples. We don't use the language since it has myriad of limitations, poor documentation, etc. For any questions about the language you should use the Unity docs and forum.
     
  28. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,245
    How can I get around this?
     
  29. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @theraider, wait until the file is written to disk before attempting to use it. Take the screenshot then wait a couple seconds before using.
     
  30. JonnyHilly

    JonnyHilly

    Joined:
    Sep 4, 2009
    Posts:
    749
    Use an ienumerator function with yield in it to wait till the screenshot is finished before continuing.
     
  31. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    414
    I'm attempting to fetch the local user's Likes from the server. Doing the graph request tests on the API Explorer works fine, but the Unity code I'm using isn't returning useable data. I first login, and verify things are working properly. I have also verified that the permissions are proper ("user_likes" is in the reauth permissions request). I can get albums, images, etc. It's just the Likes that don't seem to be working from the Prime31 response.

    Here's the code I'm using....
    Code (csharp):
    1.  
    2.     void getLikes()
    3.     {
    4.         Facebook.instance.graphRequest( "me?fields=likes", HTTPVerb.GET, getLikesForLocalUser_completionHandler );
    5.     }
    6.  
    7.     void getLikesForLocalUser_completionHandler( string error, object result )
    8.     {
    9.         if( error != null )
    10.             Debug.LogError( error );
    11.         else
    12.         {
    13.             var responseData = result as IDictionary;
    14.             var likeData = responseData["likes"] as IList;
    15.  
    16.             // The following 'for' loop fails, saying likeData does not exist
    17.             for(int i = 0; i < likeData.Count; i++)
    18.             {
    19.             {
    20.     }
    21.  
    The result here, as mentioned in the comment above, is that the 'likeData' object is null... which makes me think that 'likes' does not exist in the result object. When I do this exact same query on the Graph API Explorer, it returns the Likes just fine.

    Any hints as to what I may be doing wrong?

    Thanks in advance!
     
  32. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @dave, the best thing to do is enable the request debugger bool on the Facebook class. That will dump every bit of information Facebooks servers return to the log.
     
  33. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,245
    I haven't done this before, how would I do it in unityscript?
     
  34. ligrew

    ligrew

    Joined:
    Mar 14, 2013
    Posts:
    3
    What should I do if on checking session validity I receive something like this:

    Code (csharp):
    1. (Filename: /Applications/buildAgent/work/d3d49558e4d408f4/artifacts/iPhonePlayer-armv7Generated/UnityEngineDebug.cpp Line: 53)
    2. Facebook is session valid: True
    3.  
    4. (Filename: /Applications/buildAgent/work/d3d49558e4d408f4/artifacts/iPhonePlayer-armv7Generated/UnityEngineDebug.cpp Line: 53)
    5. checked session validity on server: False
    I can't even invoke: Facebook.instance.getMe(...);

    Any ideas?
     
  35. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @ligrew, that means the access token expired and you need to login the user again.
     
  36. ligrew

    ligrew

    Joined:
    Mar 14, 2013
    Posts:
    3
    Logout -> delete game on facebook -> restart app -> init Facebook -> Login -> Reauth -> Is session valid? = still nothing :/ same as before...
     
  37. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @ligrew, without log output there is absolutely nothing I can do to assist besides make guesses. Please provide all relevant logs.
     
  38. xikky

    xikky

    Joined:
    Dec 11, 2012
    Posts:
    47
    I cannot find out how to get scores for all users for an App. Meaning not just only the user's friends' score. The idea is to get a top 10 scores from all users of the app.

    Can I do this?
     
  39. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @xikky, as far as I know you cannot do that but don't take my word for it. You will most definitely want to review Facebook's Graph API documentation to see what it can and cant do.
     
  40. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,245
    So I know I know it is a 3 step process in facebook to get to being able to post (login, auth, then post), how can I do these 3 steps in a row while waiting for the previous step to finish?
     
  41. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @theraider, you just use the events. The plugin has events for both the success and failure of every asynchronous operation that occurs. If you open the demo scene and just press buttons the console will fill with every event that fires as it happens.
     
  42. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,245
    Thanks

    one more quick question, on my idevice how do I reset the apps facebook persmissions so I have to go through the login process again for testing?
     
  43. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @theraider, you should just setup a new test account in the Facebook developer portal if you need a clean slate.
     
  44. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,245
    thank you
     
  45. devbr

    devbr

    Joined:
    Dec 26, 2011
    Posts:
    65
    Hello prime31,

    I'm using Unity 4.3.3 and now graphRequest() is always returning null in callback. I tried to use Prime31.Json.useSimpleJson = true inside Awake() with no success. How can I turn on this log feature of Facebook class you mentioned to @dave? The only bool attribute I found is useSessionBabysitter...

    Thanks in advance
     
  46. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    414
    Use this:

    Code (csharp):
    1.  
    2. Facebook.instance.debugRequests = true;
    3.  
    I stuck that in my code that initializes the Facebook events.
     
  47. devbr

    devbr

    Joined:
    Dec 26, 2011
    Posts:
    65
    Thanks Dave!

    Did you solve the problem?
     
  48. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    414
    I did - The data was being parsed incorrectly on my end. I had to do it like this:

    Code (csharp):
    1.  
    2.         var responseData = result as IDictionary;
    3.         var likeData = responseData["data"] as IList;
    4.  
    5.         for(int i = 0; i < likeData.Count; i++)
    6.         {
    7.             var thisLike = likeData[i] as IDictionary;
    8.            
    9.             string likeId = thisLike["id"].ToString();
    10.             if(!doesLikeExistForUser(likeId))
    11.             {              
    12.                 FacebookLike newLike = new FacebookLike();
    13.                 localUserLikes.Add(newLike);
    14.                
    15.                 // Get the data and store it
    16.                 newLike.likeId = likeId;
    17.             }
    18.         }
    19.  
    Though now I'm having a new problem... in Unity 4.3.3, all graph requests return valid data, but Prime31 sends it back to the originating function as null.

    EDIT: I was apparently using an older version of the plugin. After updating it now works fine.
     
    Last edited: Jan 28, 2014
  49. devbr

    devbr

    Joined:
    Dec 26, 2011
    Posts:
    65
    I have the same problem. It seems prime31 is aware about this problem. Others users are complaining about this 4.3.3 issue. The workaround I'm using is letting another Json parser do the job and making requests by my own www calls. For instance:

    Code (csharp):
    1.  
    2. string token = FacebookBinding.getAccessToken();
    3. WWW www = new WWW("https://graph.facebook.com/me?access_token=" + token);
    4. yield return www;
    5. string retorno = www.text;
    6. Debug.Log(retorno);
    7. Dictionary<string,object> dict = Json2.Deserialize(retorno) as Dictionary<string,object>;
    8. Debug.Log(dict["id"]);
    9. Debug.Log(dict["name"]);
    10. Debug.Log(dict["email"]);
    11.  
    This is the Json parser I'm using:
    https://gist.github.com/darktable/1411710
     
  50. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @devbr, if you add the line below anywhere before using the Facebook class it will use an alternate JSON parser that works around the bug until Unity 4.4 drops which will hopefully have the fix.

    Prime31.Json.useSimpleJson = true;