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

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @D, for posting an image Facebook doesn't have a UI. Only the showDialog variants provide a UI.
     
  2. cjow

    cjow

    Joined:
    Feb 29, 2012
    Posts:
    132
    Hi. I've just tried to import the package but whenever I do it's riddled with compile errors. Removing the compiler definitions in various classes fixes them but I'm not sure if this has any adverse effects further down the line. Would appreciate a bit of advice.

    Thanks in advance.
     
  3. DarkJedi

    DarkJedi

    Joined:
    Apr 15, 2009
    Posts:
    48
    @CJO As I've experienced similar things, I have two suggestions:

    1. What version of Unity are you using? I'm still on 3.4.2 (because for some reason 3.5.2 creates Xcode projects that just won't link properly) and I find I have to delete and manually recreate Mike's prefabs as the older version of Unity doesn't recognised the imported ones.

    2. I use Visual Studio on a Windows box to edit my c# scripts (old habits...) and find I have to remove the compiler IF statements in the plugin bindings and managers too, as (understandably) VS doesn't recognise such syntax. That's fine for me, as my project is currently iPhone only.
    However, those definitions shouldn't stop Unity itself from compiling of course...

    HTH, Dan
     
  4. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @CTH, what @Dark said is spot on. Check those two things and make sure your target platform is set properly in the player settings.
     
  5. cjow

    cjow

    Joined:
    Feb 29, 2012
    Posts:
    132
    Therein would lie the problem then. I imported it into a version of my app that is on PC so anything to do with #if UNITY_IPHONE does not compute :p

    Will it do any harm down the line by removing the compiler definitions so it's usable on PC or shall I confine it to the version that's on my Mac?
     
  6. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @CJO, you can remove the precompiler defines safely. We will not be responsible if you try to call the methods on a non-iphone though :)
     
  7. cjow

    cjow

    Joined:
    Feb 29, 2012
    Posts:
    132
    That's no problem. Thanks for the help :)
     
  8. aigam

    aigam

    Joined:
    Dec 31, 2005
    Posts:
    170
    Hi!
    I have a weird problem (I'm using the example project):
    -If I don't have the facebook app installed, it goes to safari, and it login without problem. (so is OK)
    -If I have the facebook app installed, then it enters the facebook app to login, but it stays here only few seconds, and then returns to my game, without login. Is very weird because it means that if the user has the facebook app installed I can't login never...

    I tried other games, and they enter and login without problem.
    (All data is correctly filled, the SSO option, the url scheme, is added to plist...)

    Thks for your help
     
  9. aigam

    aigam

    Joined:
    Dec 31, 2005
    Posts:
    170
    Also, when the user tries to login with twitter Oauth, it gives us a PIN, but we don't know how to use it.
    How we can use/avoid the pin?
     
  10. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @aigim, for Twitter you didn't setup your app properly. It needs a callback URL. For Facebook the syntoms you describe almost always mean your bundle ID wasn setup properly and Facebook won't log you in because of that.
     
  11. bigcheese_

    bigcheese_

    Joined:
    Sep 6, 2011
    Posts:
    31
    I'm having a problem with the Facebook plugin on iOS, after I prompt for login safari will open the login dialog and I can login just fine, but after I allow permissions, I press "Okay" on the top right, I get a message that says "Safari cannot open the page because the address is invalid.
    What could be the problem?

    Please note that the same call works on Android just fine, with the same permission list.
     
  12. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @big, Safari not being able to reopen your app means either you didn't properly setup your URL scheme or you didn't put the proper bundle ID in when setting up your Facebook app.
     
  13. bigcheese_

    bigcheese_

    Joined:
    Sep 6, 2011
    Posts:
    31
    Alright that makes sense, everything is working now, I was passing a scheme suffix URL (that I had setup on the Facebook dashboard for the app) to the loginWithRequestedPermissions( string[] permissions, string urlSchemeSuffix ) function. However once I stopped passing the urlSchemeSuffix everything worked just fine. Any idea what could be the problem? do I need to pass the suffix in the (FB_APPID_URLSUFFIX) form ?

    Another question on the side, Is there a way to receive an event upon successful posting on Facebook? Like with Twitter on iOS.
    Also I noticed that the Twitter event is only available for the iOS version of Twitter and not Android, is there a way to receive one on Android?
     
  14. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @big, only the suffix itself should be passed through in login but the whole string needs to be present in the actual URL scheme. There are many different ways to post to Facebook and they all have events associated with them. See the *EventListener class for examples along with the demo scene. On Android there is a requestSucceededEvent for all Twitter API calls.
     
  15. Matkins

    Matkins

    Joined:
    Aug 24, 2009
    Posts:
    152
    Hello Prime31,

    I'm confused about the Social Networking plugin. I had it working on iOS a long time ago and now I come to sort it out for Android too. I've downloaded the latest version and even the testSupportIOS files are kicking up errors.

    I spotted in one of the scripts that it says to use the following block of code to support iOS and Android simultaneously.
    Code (csharp):
    1. #if UNITY_ANDROID
    2. using FacebookAccess = FacebookAndroid;
    3. #elif UNITY_IPHONE
    4. using FacebookAccess = FacebookBinding;
    5. #endif
    But putting that in my Menu.cs script gives me this error.
    Thanks for your support.
    Matkins
     
  16. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @matkins, it sounds like you may have some old files mixed in with the new ones. Be sure to delete all the old files before importing the latest version. There were major API and class changes between versions.
     
  17. devGuillaume

    devGuillaume

    Joined:
    Feb 10, 2012
    Posts:
    23
    Hello,

    Contrary to Steven, the facebook app is already under the Games category (subcategory Adventure), and I still have the same error:
    Code (csharp):
    1.  
    2. (Filename: /Applications/buildAgent/work/300357e52574df36/Runtime/ExportGenerated/iPhonePlayer-armv7/UnityEngineDebug.cpp Line: 43)
    3.  
    4. -> applicationDidResignActive()
    5. -> applicationDidEnterBackground()
    6. -> applicationWillEnterForeground()
    7. -> applicationDidBecomeActive()
    8. Successfully logged in to Facebook
    9.  
    10. (Filename: /Applications/buildAgent/work/300357e52574df36/Runtime/ExportGenerated/iPhonePlayer-armv7/UnityEngineDebug.cpp Line: 43)
    11.  
    12. Unloading 3 Unused Serialized files (Serialized files now loaded: 0 / Dirty serialized files: 0)
    13.  
    14. Unloading 2 unused Assets to reduce memory usage. Loaded Objects now: 135. Operation took 17.567751 ms.
    15. app access token retrieved: 208082439215773|H1nF4smKMf_w-8VFxIQYB-j7ItI
    16.  
    17. (Filename: /Applications/buildAgent/work/300357e52574df36/Runtime/ExportGenerated/iPhonePlayer-armv7/UnityEngineDebug.cpp Line: 43)
    18.  
    19. InvalidCastException: Cannot cast from source type to destination type.
    20.   at Facebook+<postScore>c__AnonStorey1.<>m__2 (System.String error, System.Object obj) [0x00000] in <filename unknown>:0
    21.   at Prime31.P31RestKit.processResponse (UnityEngine.WWW www, System.Action`2 onComplete) [0x00000] in <filename unknown>:0
    22.   at Prime31.P31RestKit+<send>c__Iterator0.MoveNext () [0x00000] in <filename unknown>:0
    23.  
    24. (Filename:  Line: -1)
    Thoughts?

    I pressed the Get App Access Token and waited for the output shown above before pressing the Post Score button. Should anything be done with this app token? I don't see it used in the sample code.

    Thank you!
     
  18. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @dev, your error is totally different and has mention at all of the app access token. It's hard to say exactly what the error is but a cast exception could be due to your completion handler trying to cast or an incorrect parameter. The demo scene has a working test that you can use to model your code.
     
  19. devGuillaume

    devGuillaume

    Joined:
    Feb 10, 2012
    Posts:
    23
    @Prime31, I've seen people in this thread mentioning that scores could be posted and retrieved but that they didn't show up on the users' walls. Is that the expected behavior? I'm starting to wonder if I I should just post standard messages with the score in it instead of trying to use the postScore method.
    Thanks!
     
  20. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @dev, Facebook will not post scores from a mobile app to anyone's wall. That is only for apps on Facebook itself.
     
  21. devGuillaume

    devGuillaume

    Joined:
    Feb 10, 2012
    Posts:
    23
    Ok, thanks for the fast answer, that simplifies things!
     
  22. Matkins

    Matkins

    Joined:
    Aug 24, 2009
    Posts:
    152
    @prime,

    I'm still confused. I've downloaded it from the email receipt, created a new empty project, imported package and this is what i see:

    http://i.imgur.com/EUvxW.png
     
  23. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @matkins, set your project to iOS.
     
  24. Matkins

    Matkins

    Joined:
    Aug 24, 2009
    Posts:
    152
    The project needs to support both Android and iOS
     
  25. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @matkins, we cannot reproduce what you are seeing when downloading the latest versions of the plugin for iOS and Android and importing them into a fresh project. Ensure that you have both versions installed in a clean, empty project set to either iOS or Android.
     
  26. RazorCut

    RazorCut

    Joined:
    May 7, 2009
    Posts:
    393
    Hi Prime,

    I'm performing a "apprequests" dialogs request and I successfully see the friend selection dialog. But I can't figure out why I'm not getting a callback that provides me with the list of friends that were selected.

    I get a successful callback when I use FacebookManager.dialogCompletedEvent but not with FacebookManager.customRequestReceivedEvent.

    What's the proper way for me to get the friends that were selected from the "apprequests" dialog with the plugin? Thanks!
     
  27. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @Razor, if I recall from the Facebook docs you have to parse the request ID's from the url passed to dialogCompletedWithUrlEvent
     
  28. RazorCut

    RazorCut

    Joined:
    May 7, 2009
    Posts:
    393
    Thanks, I'll give that a try!
     
  29. jfred1979

    jfred1979

    Joined:
    May 31, 2012
    Posts:
    6
    @Razor: Have you had success with the user's actually receiving the invites using this method? I'm using the apprequest dialog in the exact same way and even though I'm getting both successful dialogCompletedEvent and dialogCompletedWithUrlEvent callbacks (with a URL that contains all the user IDs I sent the request to) for some reason the user's aren't actually receiving it. Could be something I've set up wrong on the Facebook end, but it seems odd that I'm getting successful callbacks...

    @Prime: The dialogCompletedEvent doesn't necessarily give any indication of the success or failure of the actual Facebook request, right? It's just an indication that the dialog window closed successfully?
     
  30. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @jfred, the event indicates nothing more than the dialog closed.
     
  31. aigam

    aigam

    Joined:
    Dec 31, 2005
    Posts:
    170
    Thks, now is perfect!
    Maybe you need to add a FAQ, to avoid the same questions every day
     
  32. Matkins

    Matkins

    Joined:
    Aug 24, 2009
    Posts:
    152
    @prime, everything appears to be working on Android now, cheers for the help. Unfortunately things on the iOS side are now broken. When building from Xcode i get this error:

    Any ideas?
     
  33. zehreken

    zehreken

    Joined:
    Jun 29, 2009
    Posts:
    112
    Hello again,
    I have a problem with html entities, special characters like ç, ö, ü etc. shows as hex html entities( 00C7; 00D5; ). Is there a simple way for decoding them? Right now I replace them manually.
     
  34. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    That was fixed in a recent update if thats for the results you get from Facebook graph api
     
  35. zehreken

    zehreken

    Joined:
    Jun 29, 2009
    Posts:
    112
    Yes, that was my problem, thanks for the reply.
     
  36. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @matkins, FBFrictionlessRequest* classes are part of Facebooks SDK. Try doing a build followed by replace to get a fresh Xcode project.
     
  37. devGuillaume

    devGuillaume

    Joined:
    Feb 10, 2012
    Posts:
    23
    Hello,

    Two questions today!

    1/ I'm successfully posting to Facebook from our game through this process:
    - call to init at game launch
    - call to post message method that checks the session validity and trigger the login if needed, then post.

    At first call, I authorize the game from the Facebook app.

    Trying to start the process again, I go to the Facebook app prefs and delete the app authorization.

    Now when I try to post again from the game, the post message completion handler has no errors but the post does not appear on the user's wall.

    What is the process to correct this? Is there a way to check that the game is authorized before posting, and ask for a new authorization if it's not?

    Or is the user decision final and they need to reinstall the app to reset everything?

    2/ I started by using the postMessage method from the plugin, and I realized that I couldn't post the same message twice, which is nice. Now I'm using the postMessageWithLinkAndLinkToImage and I've just posted the same message several times in a row. Is there something to configure to avoid the repetition, other than checking it ourselves in code?

    Thanks!
     
  38. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @dev, I believe there is a Graph API endpoint for checking if an access token is valid. You can most likely also just call extendAccessToken and if it fails you will know the token is no good. Check Facebooks docs for their recommended procedure. You will also want to consult Facebooks docs for what their duplicate content rules are.
     
  39. RazorCut

    RazorCut

    Joined:
    May 7, 2009
    Posts:
    393
    @jfred1979 Yes, so far I've had success in that the recipients can click the invite and are directed to a landing page that is set up (though not fully finished).
     
  40. C4MProdDev

    C4MProdDev

    Joined:
    Jul 9, 2009
    Posts:
    107
    Hello,

    we used recently the social networking plugin but we had to do some modification to use it:

    For Facebook :
    We needed that when facebook is open, the application is not closed.
    To do that , in the function :
    Code (csharp):
    1. - (void)authorizeWithFBAppAuth:(BOOL)tryFBAppAuth safariAuth:(BOOL)trySafariAuth
    line 218, we commented lines 247 to 266.

    For twitter:
    To show the twitter view each time the twitter button is pressed,
    line 434 in TwitterManager.mm, in function :
    Code (csharp):
    1. - (void)showTweetComposerWithMessage:(NSString*)message image:(UIImage*)image
    we commented line 437 to 442.

    We needed to know in Unity that a message has been posted. So in
    the same file line 434 function :
    Code (csharp):
    1. - (void)showTweetComposerWithMessage:(NSString*)message image:(UIImage*)image
    After an image is added, we add the following code :
    Code (csharp):
    1. [tweetSheet performSelector:@selector(setCompletionHandler:) withObject:^( int result )
    2. {
    3.     printf_console("%s Ok %d \n", __PRETTY_FUNCTION__, result);
    4.     if (result)
    5.     {
    6.         UnitySendMessage( "TwitterManager", "twitterPostSucceeded", "" );
    7.     }
    8.     [UnityGetGLViewController() dismissModalViewControllerAnimated:YES];
    9. }];
    I hope this could be usefull to someone ^^
     
  41. bigcheese_

    bigcheese_

    Joined:
    Sep 6, 2011
    Posts:
    31
    While posting my app to Apple's app store, they asked me whether I use any cryptographic encryption.
    Now I'm using the Social media plugin to post to Facebook and Twitter, do I need to obtain an SSL-Certificate ?! or is it not needed?
     
  42. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @big, SSL is handled by iOS so no need to worry about it. Only when you add your own encryption does it have to be reported.
     
  43. EricD

    EricD

    Joined:
    Sep 7, 2011
    Posts:
    128
    I've got a big issue I need to fix asap.

    Our unity game runs in Arm6, which for us is faster than arm7. However in xcode I have to add arm7 in order to submit to apple. However when I have both arm6 arm 7 in xcode I can't post to facebook anymore....

    How can I fix this?
     
  44. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @eric, the plugin files are provided as full source code so changing the architecture shouldn't affect them in any way. They will just be compiled by Xcode for each architecture separately.
     
  45. EricD

    EricD

    Joined:
    Sep 7, 2011
    Posts:
    128
    Have you got a clue as to why it doesn't work with both architectures? But it works with only one?
     
  46. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @eric, I have never seen changing the architecture affect code running before.
     
  47. EricD

    EricD

    Joined:
    Sep 7, 2011
    Posts:
    128
    Building with arm67 doesn't give the problem. Really weird.
     
  48. devGuillaume

    devGuillaume

    Joined:
    Feb 10, 2012
    Posts:
    23
    From this page and this answer, it seems that I indeed need to call extendAccessToken().
    I added a button to do just this in your sample scene and this is the output I get:
    Code (csharp):
    1. (Filename: /Applications/buildAgent/work/300357e52574df36/Runtime/ExportGenerated/iPhonePlayer-armv7/UnityEngineDebug.cpp Line: 43)
    2.  
    3. -> applicationDidResignActive()
    4. -> applicationDidEnterBackground()
    5. -> applicationWillEnterForeground()
    6. -> applicationDidBecomeActive()
    7. Successfully logged in to Facebook
    8.  
    9. (Filename: /Applications/buildAgent/work/300357e52574df36/Runtime/ExportGenerated/iPhonePlayer-armv7/UnityEngineDebug.cpp Line: 43)
    10.  
    11. facebookDidExtendTokenEvent: 12/16/1962 02:31:28
    Do you have any idea why the new expiry date would be in the past? The only thing I could think of is check the device date, it is set up properly.
     
  49. aigam

    aigam

    Joined:
    Dec 31, 2005
    Posts:
    170
    Hi!
    Somebody know how to do a "like to a page" option?
    I tried the "pageid/likes" but it returns the likes of the pageid, doesn't create a like.

    Thks for any help
     
  50. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @dev, that is quite odd. It isn't even 1970 which I would expect to be the lowest possible using epoch time. I'll see of I can reproduce the issue.


    @aigam, consult the Facebook Graph API docs for the details on what is possible and the parameters/path required.