Search Unity

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

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

  1. gregdevice

    gregdevice

    Joined:
    Feb 8, 2009
    Posts:
    11
    Ok, thanks for the quick reply. Got it. I was thinking there was an additional prefab involved.
     
  2. rextr09

    rextr09

    Joined:
    Dec 22, 2011
    Posts:
    416
    Hi, What is the best place to call FacebookBinding.init() function? Is it okay to call it every time before posting to wall? Or should we call it when our game started? But this time facebook will be initialized unnecessarily if a player does not use it at all. Does init() function requires any processing power or takes much space in memory when called? Thanks.
     
  3. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @rextr, call it once in your initial loading scene. It has next to no overhead.
     
  4. rextr09

    rextr09

    Joined:
    Dec 22, 2011
    Posts:
    416
    Omg, you literally give "live support". Thanks again and again for another quick answer.
     
  5. e5an

    e5an

    Joined:
    Jul 6, 2012
    Posts:
    93
    I just updated to 1.5.2 and it made my XCode build fail with 19 (or rather, "too many to continue") errors.
    They are all "Semantic Issue: Use of undeclared identifier '',,," and they are all in FacebookManager.mm

    Wha happen??

    I reimported the assets and the test scenes fail to build too.
     
    Last edited: Sep 7, 2012
  6. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
  7. e5an

    e5an

    Joined:
    Jul 6, 2012
    Posts:
    93
    Late last night I just reimported from Unity and redownloaded and still got the errors so was stressing out a bit, but this morning I trashed everything from the Finder, and then imported from the Asset store, and now it works fine. Thanks. I noticed FaceBookBinding had some functions that disappeared in the new version, (whatever the renew access token one was, I assume we don't need to do that any more? And the show dialog with options.) You said the Facebook SDK is entirely new- so is there a changelog that explains what all is different in this one from the previous version?
     
  8. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @milo, Facebooks changeling details all the changes. Extend access token is still possible through the Graph API and you can still show all kinds of dialogs via the showDialog method which takes an optional dictionary. Some redundant methods were removed also.
     
  9. gregdevice

    gregdevice

    Joined:
    Feb 8, 2009
    Posts:
    11
    Hi Prime, I'm new to this and yes I'm using UnityScript ;). With that out of the way, can you lend some advice on what I'm missing here? My code is pasted below. I'm trying to post some text to a users Facebook wall. When a FB button is clicked it runs the LogInToFacebook() function which opens the Facebook app (if installed) and once logged in it sometimes comes back to the Game app and sometime not ( I used http://www.google.com for the return URL in Facebook Dev.). But it does not post anything and never calls the post as successful or failed.

    Code (csharp):
    1. function Start(){
    2.    
    3.     FacebookBinding.init("-MyNumber-");
    4. }
    5.  
    6.  
    7.  
    8. function LogInToFacebook(){
    9.  
    10.     if(FacebookBinding.isSessionValid() == false) {
    11.        
    12.         FacebookBinding.login();
    13.        
    14.         print("Logging in Facebook User...");
    15.          
    16.     }
    17.     else {
    18.         PlayerIsLoggedIn_PostToTheirWall();
    19.        
    20.         print("User Already Logged Into Facebook.");
    21.     }
    22. }
    23.  
    24.    
    25. function OnEnable(){
    26.     FacebookManager.loginSucceededEvent += facebookLoginSuccessful;
    27.     FacebookManager.dialogCompletedEvent += facebookPostSuccessful;
    28.     FacebookManager.dialogFailedEvent += facebookDialogFailed;
    29. }
    30.  
    31. function OnDisable(){
    32.     FacebookManager.loginSucceededEvent -= facebookLoginSuccessful;
    33.     FacebookManager.dialogCompletedEvent -= facebookPostSuccessful;
    34. }
    35.  
    36.  
    37. function PlayerIsLoggedIn_PostToTheirWall(){
    38.    
    39.     yield WaitForSeconds (2);
    40.     Facebook.instance.postMessage( "Posted!", null );
    41.    
    42.     print("Attempting to Post to Facebook Wall...");
    43.  
    44. }
    45.  
    46.  
    47. function facebookLoginSuccessful(){
    48.    
    49.     print("Facebook Login Successful");
    50. }
    51.  
    52.  
    53. function facebookPostSuccessful(){
    54.    
    55.     print("Facebook Wall Post Was Successful");
    56.  
    57. }
    58.  
    59. function facebookDialogFailed(){
    60.  
    61.     print("Facebook Wall Post Failed");
    62.  
    63. }
     
  10. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @greg, you can forget about posting to the wall if you can't even log a user in properly. If you had to enter a URL in the Facebook app setup page you are not properly creating an iOS native app. There is no URL field for native apps. Review Facebooks documentation with regard to native iOS app setup, properly setup your Facebook app and then logins should start working once that is all sorted out.
     
  11. gregdevice

    gregdevice

    Joined:
    Feb 8, 2009
    Posts:
    11
    Thanks, I think I have everything setup correctly. It's only under the Deauthorize Callback URL that I put the URL. And I have "web" selected there as well (taken from a previous suggestion). In the Basic options I have it as a Native App with all Bundles and IDs in place.
     
  12. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @greg, if Facebooks app is not opening your app every time something isnt properly setup. You should use the demo scene and watch the logs while testing and all the data Facebook returns is dumped there.
     
  13. e5an

    e5an

    Joined:
    Jul 6, 2012
    Posts:
    93
    I built the two test scenes with the new version and none of the buttons are working.
    The "Initialize Facebook" button gives the message in the XCode Console; "[6730:707] no Facebook session available".
    What does that mean?

    I wouldn't expect any of the other buttons to work after that but the "Is Session Valid?" button returns "False" and the "Get Access Token" just says

    " access token: "

    "Login" flips over to the Facebook blue bar UI with the title "Error" (cancel) (ok) and red box text saying "An error occurred. Please try again later.
    "Graph Request (me)" crashes the app.

    The "Initialize Twitter" button does nothing. The "Login to Twitter" button gives a "Woah there! The request token for this page is invalid.... etc." red box message.
    [6921:707] https://twitter.com/oauth/authorize?oauth_token=(null)
    basically nothing is getting a token for anything now.
     
  14. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @kiloblargh, your description sounds like it is working perfectly fine but you failed to enter your own personal Facebook app info and Twitter info. Read through the code and you will have a hard time missing where to enter your own personal app information.
     
  15. Amitloaf

    Amitloaf

    Joined:
    Jan 30, 2012
    Posts:
    97
    I have the same problem and you answered this one's problem via mail. Any idea what's the problem?

     
  16. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @amit, consult Facebooks docs for the data they will return. It will be sent to the completion handler directly as they send it back.
     
  17. Amitloaf

    Amitloaf

    Joined:
    Jan 30, 2012
    Posts:
    97
    Can you help me on this one? I'm kinda lost. Is the data sent back for "me/friends" supposed to be the same as "me"? If so, where is the friends list?
     
  18. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @amit, you really need to read Facebooks Graph API reference. The plugin exposes it for you and Facebook has excellent documentation of what each graph path returns. We don't work for Facebook and are not familiar with their enormous API but ten seconds in their docs shows that "me" returns the logged in users info and "me/friends" returns their friends.
     
  19. Dhaval Sarvaiya

    Dhaval Sarvaiya

    Joined:
    Jul 28, 2012
    Posts:
    9
    hey i am not able to find the prime31 menu in menu bar after importing it, can you help me what are other ways to add the app id in info.plist addition
    i am stuck and its really urgent as i need to update my client,
     
  20. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @dhaval, just click in the menu bar and Unity will update it adding the prime31 menu item. You can also just follow Facebooks instructions on how to add your URL scheme in Xcode.
     
  21. trop

    trop

    Joined:
    Sep 5, 2012
    Posts:
    41
    hi prime!i encountered error while running the app, it says Facebook Binding cannot be found.pls help me on this.thanks

    Assets/Plugins/SocialNetworking/testSupportIOS/FacebookGUIManager.cs(13,24): error CS0246: The type or namespace name `FacebookBinding' could not be found. Are you missing a using directive or an assembly reference?
     
  22. Amitloaf

    Amitloaf

    Joined:
    Jan 30, 2012
    Posts:
    97
    First of all, thanks for all the quick responses and sorry for all the questions.
    Now for the question :D

    Is there a quick way to get the logged in user's id (opposed to the screen name for which there's a funcion in TwitterBinding)
    Or is the only way to just request for users/show with the screen name and then take it out of there?
     
  23. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @trop, set your player settings to iOS


    @amit, check Twitters API docs. There is a method they offer that grabs the users info but I don't recall the exact path and parameters it requires.
     
  24. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    First, how do we call this through the Graph API? What URL should we use?
    Secondly, according to the first answer on this page (link following), it sounds like we will need the user to repeatedly grant our app permission to use Facebook (every hour?), so I'm not sure what the purpose is anymore of even having ExtendAccessToken. http://stackoverflow.com/questions/...n-of-offline-access-when-you-use-token-both-i

    Please explain, thanks!
     
  25. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @jerotas, both the demo scene and the documentation show how to make Graph API requests. Have you looked at them yet? If not, that should be the first thing you should do before trying to use the plugin. Access tokens have limited lifespans. You can and should be using the Graph API to extend access tokens on each launch.
     
  26. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Thanks Prime. What is the lifespan of the access token if you extend it? Is it unlimited or not?
     
  27. pogoli

    pogoli

    Joined:
    May 30, 2008
    Posts:
    41
    but what is the actual graphAPI call to extend the token. I haven't found it in the docs yet, it would be fantastic if someone could just post it here. Thanks!
     
  28. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Exactly pogoli. I am making plenty of working Graph API requests already. I was asking what method name / URL I should be using to do "extend access token", which you didn't answer Prime31. And where I can I actually find the documentation? I don't seem to have it in my Unity project after importing the newest package (not purchased from Asset store, but from Prime31 website).

    Thank you in advance!
     
  29. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @jerotas, consult Facebooks docs for access token lifespan. It changes on occasion.


    @pogoli, I believe it is "extendAccessToken" but you will want to check the Graph API docs to be certain.
     
  30. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Since it is a method that used to be provided by your plugin, it would be nice if you included a working call to this in the demo scene in your package. Thank you.
     
  31. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @jerotas, it used to be a method in Facebooks SDK. It is no longer so consult their docs or open a feature request with Facebook to bring the method back. We obviously cannot wrap the hundreds of Graph API end points up.
     
  32. pogoli

    pogoli

    Joined:
    May 30, 2008
    Posts:
    41
    Why not just wrap the Prime31 plugin call to use the graphAPI request?

    I have been searching the facebook docs for a bit already, they didn't name it anything so convenient if its even in there. I'll have to dig into them more when I get home.
     
  33. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Ditto pogoli, I can't find this anywhere.
     
  34. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @pogoli and @jerotas, I searched Facebook's docs for "extend access token" and the first result that came up was this:
     
  35. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    trop, go into the FacebookBinding.cs file (it is there) and remove the "#if UnityIOS" thing at the beginning and the matching comment at the end of the file. There's another file you will have to do this on also.
     
  36. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    That you Prime31, I will try that as soon as I can build normally. The newest SocialNetworking plugin gives me 5 errors in xCode. I did delete my 2 SocialNetworking folders prior to importing the package. Here's one of the errors:
    ------------------------------
    Undefined symbols for architecture armv7:
    "_OBJC_CLASS_$_FBRequest", referenced from:
    objc-class-ref in FacebookManager.o
    "_OBJC_CLASS_$_Facebook", referenced from:
    objc-class-ref in FacebookManager.o
    (maybe you meant: _OBJC_CLASS_$_FacebookManager)
    "_OBJC_CLASS_$_FBSession", referenced from:
    objc-class-ref in FacebookManager.o
    "_OBJC_CLASS_$_FBRequestConnection", referenced from:
    objc-class-ref in FacebookManager.o
    ld: symbol(s) not found for architecture armv7
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    --------------
    Please let me know what I need to do to be able to build again.
    Thank you.
     
  37. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @jerotas, did you run the clean command on your Xcode project? Did all the files get copied into your Xcode project?
     
  38. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    It cleaned by itself I assume, since it said "project successfully cleaned" during build. Then it subsequently failed. How can I check if all files got copied to xCode?
     
  39. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @jerotas, you have to manually clean the project whenever major changes are made. Unity's attempt to clean prelaunch doesnt work most of the time. You can see if the files are present by making sure the files in Assets/Editor/SocialNetworking ended up in the Xcode project in a folder of the same name. The Finder/Grown/NotificationCenter popup will let you know if they were copied as well.
     
  40. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    It was a file that didn't automatically check into SVN for some reason (weird .a extension?). I think this actually happened last time haha. I'm good, thanks.
     
  41. trop

    trop

    Joined:
    Sep 5, 2012
    Posts:
    41
    hi prime i got this error when run it in xcode ..EXC_BAD_ACCESS(code=1, address=0x0)

    hi prime was able to fix it anyway thanks, one more thing when i try to click the button it says Facebook Manager not found! i actually modified the login button which i put a login icon/png.Do you have any idea how to fix it?thanks
     
    Last edited: Sep 12, 2012
  42. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @trop, the error indicates that you do not have a FacebookManager prefab in your game. You should put it in your initial loading scene so that it is ready to go at any time.
     
  43. pogoli

    pogoli

    Joined:
    May 30, 2008
    Posts:
    41
    Ah. I wasn't putting a space between 'access' and 'token'.

    Obviously... you shouldn't wrap all the graph API calls. However, I thought one of the goals of your Social Networking plugins was to have the same call signature between android and iOS. Now they diverge. If you wrapped just that one graph api call, then you would continue to succeed with the goal.

    On the other other hand... I presume that when facebook updates the android sdk they will drop it as well and then you will be back in sync when you drop it from yours...
     
  44. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @pogoli, expect Facebook to remove that method from Android as well as soon as they release the new Android SDK. If you simply use a Graph API call the two will work fine together.
     
  45. pogoli

    pogoli

    Joined:
    May 30, 2008
    Posts:
    41
    Fantastic! Thanks for the help with that @prime31.

    I am running into another problem now. When I build into XCode with the latest plugin updates I am getting the following types of errors in FacebookManager.mm:

    Use of undeclared identifier 'FBSession'; did you mean 'PBVersion'?
    Use of undeclared identifier 'FBSessionLoginBehaviorWithFallbackToWebView'
    Use of undeclared identifier 'FBRequestConnection'
    Use of undeclared identifier 'connection'; did you mean 'NSConnection'?

    there are more than one of each of these and after about 20, xcode stops logging them. Is there something I am missing?

    I admit that I didn't wipe the plugin before updating. Is that causing this, or is there something else I need to do to fix this problem?

    Thanks!
     
  46. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @pogoli, if you didnt wipe the old files you will 100% certainly have errors. This was a major update with a totally new SDK. You need to remove all old files, reimport the plugin, do a Build followed by Replace and then make sure to Clean your Xcode project to wipe the cached object files.
     
  47. pogoli

    pogoli

    Joined:
    May 30, 2008
    Posts:
    41
    Yes, that did help. I am not getting any more of those errors but now I'm getting linking errors.

    "_OBJC_CLASS_$_FBRequest", referenced from:
    objc-class-ref in FacebookManager.o
    "_OBJC_CLASS_$_Facebook", referenced from:
    objc-class-ref in FacebookManager.o
    (maybe you meant: _OBJC_CLASS_$_FacebookManager)
    "_OBJC_CLASS_$_FBSession", referenced from:
    objc-class-ref in FacebookManager.o
    "_OBJC_CLASS_$_FBRequestConnection", referenced from:
    objc-class-ref in FacebookManager.o

    I deleted all the Prime31/SocialNetworking folders from Editor and Plugins Folders and imported both the iOS and Android plugins. (I am in iOS mode currently). I deleted my ios build folder and xcode derived-data folders, and "cleaned" the project for good measure.


    How do I eliminate these linking errors?
     
  48. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @pagoli, the errors almost look like the entire Facebook SDK is missing. Do you see the SDK in the Frameworks folder in Xcode? Are you building for ARM7 only as well? Are you using version control? Some older VC systems like CVS and SVN cause issues with static libraries. Does the plugin compile when imported into an empty project?
     
  49. pogoli

    pogoli

    Joined:
    May 30, 2008
    Posts:
    41
    @prime31 I am building for ARM6 only. Our app runs out of memory and crashes when built for ARM7 only.
    I see libFacebookSDK.a in the Frameworks directory, if that's the one you mean.
    We are using svn, but not with the xcode project that unity built.
    I will try it in an empty project.
     
  50. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @pogoli, ARM6 is dead as of today. Apple dropped support for it and so did we. It isn't even an option with the latest iOS SDK.