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

    donlien

    Joined:
    Apr 13, 2009
    Posts:
    229
    Hi, byerdelen, would you please tell me how did you make it work?

    It seems I have the same problem with login issue.

    Every time the isLoggedIn() return false when my app just launched by tapping icon, and it need to be kicked out and login by FB app then re-load my app again. ( UIApplicationExitsOnSuspend is checked, so my app quit totally, won't stay in background. ) At that time isLoggedIn() return true.

    After my app quit, the whole process will repeat again.

    How did you solve this problem?

    Thanks,
     
  2. donlien

    donlien

    Joined:
    Apr 13, 2009
    Posts:
    229
    Hi, Prime,

    After testing Doodle Jump and my app with Prime31, I guess the "isLoggedIn()" has some bug in it.

    In Doodle Jump, if I log out in the option menu, when I wanna post score, it is the same procedure - FB app pop up, ask permission, come back app. But even if I quit, delete icon in the task bar, next time I tap Doodle Jump, it show "logged in" state in option page.

    In my app with Prime31, even if I can post message to the wall, the "isLoggedIn()" still return false to me.

    So...I think this should be a bug of Prime31 plugin.

    Would you please fix it? Thank you.
     
  3. donlien

    donlien

    Joined:
    Apr 13, 2009
    Posts:
    229
    Dear Prime, pleeeeese tell me, will you or won't you fix the issue ? :(

    I have good reasons not to unchecked the "UIApplicationExitsOnSuspend" to build my app.

    For login 1 time to quit app is acceptable, but login every time to quit app is too ugly for my users.

    I know you are the expert. Could you pleeeeese just help me to solve this problem ? ( How to proceed login logout issue just like Doodle Jump ? )

    Thank you very much.
     
  4. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @donlien, Facebook's SDK does not support saving sessions when the app exits on suspend. I added in a few tricks to the plugin to get this. Download the latest version for the update.
     
  5. donlien

    donlien

    Joined:
    Apr 13, 2009
    Posts:
    229
    Thank you very much. :)

    I've been over 24 hrs without sleep. So let me try it about 8 hrs later.

    Seeya, Thanks again.
     
  6. donlien

    donlien

    Joined:
    Apr 13, 2009
    Posts:
    229
    Dear Prime, FYI, I've Updated the new package "SocialNetworking_2011-08-29.unitypackage" just now.

    There is a Error appear to Unity here (in GameCenterAchievement.cs, Line 21, [EDITED] and GameCenterAchievementMetadata.cs, Line 21; GameCenterLeaderboard.cs, Line 17; GameCenterPlayer.cs, Line 18; GameCenterScore.cs, Line 24):

    ArrayList list = (ArrayList)MiniJSON.JsonDecode( json );

    I found you have modified the code of MiniSON, so I changed "J" into "j", then the error was gone:

    ArrayList list = (ArrayList)MiniJSON.jsonDecode( json );
     
    Last edited: Aug 30, 2011
  7. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    MiniJson was refactored so all plugins that use it will need a minor change of changing the J to a j and the D to a d. We will push out updates soon so they are all on the same version.
     
  8. donlien

    donlien

    Joined:
    Apr 13, 2009
    Posts:
    229
    Dear Prime, I am sorry I have to tell you, there is something wrong in the new version. :(

    Whatever I call "FacebookBinding.loginWithRequestedPermissions( new string[] { "publish_stream", "offline_access" } )" or "FacebookBinding.login()", the plugin will stay in Facebook and won't come back to app again.
     
  9. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @donlien, set your URL scheme properly or Facebook cannot return you to your app.
     
  10. donlien

    donlien

    Joined:
    Apr 13, 2009
    Posts:
    229
    Oops, it has been changed into the wrong number after importing new package. :p

    I'll try again now.
     
  11. donlien

    donlien

    Joined:
    Apr 13, 2009
    Posts:
    229
    Hi, Prime, You are right !! :)

    My FB app id was gone, so it stay in FB and won't come back.

    Now it works fine whatever the "UIApplicationExitsOnSuspend" is checked or unchecked. ;)

    Thank you very much !!!!

    It save me !!!!!:D
     
  12. donlien

    donlien

    Joined:
    Apr 13, 2009
    Posts:
    229
    Hi, Prime, I have a question about Twitter login.

    I've seen these messages on twitter developer page:

    There are 2 strings named as "Access token" "Access token secret".

    When will I need these 2 string?
     
    Last edited: Sep 1, 2011
  13. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @donlien, all you need is what the documentation tells you is necessary. Here is a snippet from the docs:

     
  14. bjohnson8704

    bjohnson8704

    Joined:
    Jan 30, 2011
    Posts:
    54
    Hey Prime31,

    I just downloaded the Social Networking Plugin update and tried to import the package and I'm getting the following error:

    I can't really figure out what the cause is, but I'm guessing that some update to the MiniJSON.cs file is causing the error with the GameCenter plugin. For the time being I just went back to the old version, but it would be nice to be able to get the twitter image posting to work. :) Any idea on how to solve this?

    Thanks

    Blake
     
  15. EyeSix

    EyeSix

    Joined:
    Sep 7, 2010
    Posts:
    80
    bjohnson8704 - I had the same issue, but you can easily fix it by opening MiniJson and checking the jsonDecode function. Just change the name in the broken scripts so that they match (it's a capital letters thing, for me it was just a case of making the initial J lowercase). I think it's just an oversight in this build - prime31 said he was pushing out a fix about 6 comments ago :)
     
    Last edited: Sep 8, 2011
  16. bjohnson8704

    bjohnson8704

    Joined:
    Jan 30, 2011
    Posts:
    54
    EyeSix,

    Thanks! That did the trick. Guess I should've scrolled up a few comments. :)


    edit: ah, I actually had corrected the problem in the one script I posted, but I didn't notice that it threw an error in the GameCenterAchievementMetadata.cs script. Guess that's what I get for using tired eyes. :p
     
    Last edited: Sep 8, 2011
  17. bjohnson8704

    bjohnson8704

    Joined:
    Jan 30, 2011
    Posts:
    54
    New little problem that I can't seem to figure out. The twitter image posting is working just fine, but the text that is being posted is: "image me up". I can't find where this could possibly be coming from as the following code is what I'm using to make the twitter post:

    I've searched all the scripts that have anything to do with twitter posting(as far as I can tell), and can't find anything that would cause this. The text was posting properly before I added the image in. Any idea what could be causing this?
     
  18. EyeSix

    EyeSix

    Joined:
    Sep 7, 2010
    Posts:
    80
    I'd take a guess that the message + the URL is longer than 140 characters? What is the full pathToImage? I've not tried posting an image to Twitter... yet... :)
     
  19. bjohnson8704

    bjohnson8704

    Joined:
    Jan 30, 2011
    Posts:
    54
    Thanks for the reply again. :)

    Printed the path as follows so I'm guessing that the file path is longer than 140 total characters:

    And the actual post that shows up on twitter is definitely shorter than the 140 limit:

    My conclusion would be that there's something that is triggering the post edit in the source code somewhere based off the file path length even though it ends up being under 140 once it's posted to twitter. Completely forgot about the possibility of it being in xCode, I guess I'll try to take a look into that and see if I can figure it out.

    Thanks!


    edit:

    I'm guessing it's this line of code located in "TwitterManager.mm" although I'm not sure how I could go about fixing it as it's a little beyond my knowledge:

    I guess I could get away with just changing that string for the moment, but I would like to be able to post unique messages depending on different game modes once Droppin' Bombs hits the market and just doing a quick edit there won't allow for that of course. Any help would be greatly appreciated. :)

    Thanks!
     
    Last edited: Sep 8, 2011
  20. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    Oops. Either delete that line or grab the updated package which has the fix. If you grab the latest GameCenter package as well it has the new MiniJSON changes.
     
  21. Masashi-Wada

    Masashi-Wada

    Joined:
    Jul 6, 2010
    Posts:
    87
    Hi, Prime31.

    I am using Social Networking Plugin of android and ios.
    SocialNetworking_2011-08-29.unitypackage
    SocialNetworkingAndroid_2011-08-31.unitypackage

    Is the function which gets the followers info of Twitter valid at iOS?
    Or will the function which gets a follower as well as android be added in the near future?
    My wish is that this function can use by both iOS and android.
     
  22. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @Masashi, grab the latest update that just went live. It has a new Twitter method that lets you call any method in their API now.
     
  23. Masashi-Wada

    Masashi-Wada

    Joined:
    Jul 6, 2010
    Posts:
    87
    Hi, Prime31!
    Thank you for the new version. I will use this.
     
  24. Masashi-Wada

    Masashi-Wada

    Joined:
    Jul 6, 2010
    Posts:
    87
    Hi, prime31.
    Apart from it, I checked the condition in which an application crashes with SNS plug-in of Android.
    used version, SocialNetworkingAndroid_2011-09-01.unitypackage

    I am using TwitterTestScene.
    A login button is pushed after an initialization button.
    Account information was inputted into the dialog and the "Authorize" button was pushed.
    The application crashed and left the following log to ddms.

    09-11 16:50:33.227: WARN/dalvikvm(7907): threadid=25: thread exiting with uncaught exception (group=0x2aac87d8)
    09-11 16:50:33.237: ERROR/AndroidRuntime(7907): FATAL EXCEPTION: Thread-28
    09-11 16:50:33.237: ERROR/AndroidRuntime(7907): java.lang.IllegalArgumentException: Cannot get String from a null object
    09-11 16:50:33.237: ERROR/AndroidRuntime(7907): at org.scribe.utils.Preconditions.check(Preconditions.java:80)
    09-11 16:50:33.237: ERROR/AndroidRuntime(7907): at org.scribe.utils.Preconditions.checkNotNull(Preconditions.java:27)
    09-11 16:50:33.237: ERROR/AndroidRuntime(7907): at org.scribe.utils.StreamUtils.getStreamContents(StreamUtils.java:20)
    09-11 16:50:33.237: ERROR/AndroidRuntime(7907): at org.scribe.model.Response.parseBodyContents(Response.java:40)
    09-11 16:50:33.237: ERROR/AndroidRuntime(7907): at org.scribe.model.Response.getBody(Response.java:66)
    09-11 16:50:33.237: ERROR/AndroidRuntime(7907): at org.scribe.oauth.OAuth10aServiceImpl.getAccessToken(OAuth10aServiceImpl.java:67)
    09-11 16:50:33.237: ERROR/AndroidRuntime(7907): at com.prime31.TwitterPlugin$2.run(TwitterPlugin.java:139)
    09-11 16:50:33.237: ERROR/AndroidRuntime(7907): at java.lang.Thread.run(Thread.java:1096)
    09-11 16:50:33.247: WARN/ActivityManager(179): Force finishing activity com.snstest.dev/com.unity3d.player.UnityPlayerActivity

    This crash was not seen by GalaxyS (OS2.3).
    However, it always saw by IS04 (OS2.2).
     
  25. Masashi-Wada

    Masashi-Wada

    Joined:
    Jul 6, 2010
    Posts:
    87
    sorry. I forgot that it was an iOS group here.
     
  26. golden_gate

    golden_gate

    Joined:
    Jul 22, 2009
    Posts:
    81
    Prime31,

    Can I use the twitter and facebook plugin to post an image to twitter and/or facebook from within an iOS game? I would allow the user to take a snapshot of a screen and then post.

    The next case is a small video clip. Some mobile games show video replays of different game scenes. I also want to be able to post a video to facebook from within the Unity IOS game.

    Thanks!
     
  27. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @golden, you can post images with the plugin but not videos.
     
  28. bambamyi

    bambamyi

    Joined:
    Nov 26, 2008
    Posts:
    90
    Quick question:

    When I use showOauthLoginDialog, I see twitter window comes up, and I put my user and password, and when I approve the app, I get a token that informs me to enter into the app. I don't know what to do at this point. Isn't the plugin designed to take this information and keep the user logged in? Thanks for the help!
     
  29. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @bambamyi, sounds like you didn't properly setup your app on the Twitter portal. It needs to be setup as a web app which means it needs a callback URL set. The URL does not have to be a real one. You can just stick http://www.google.com in there.
     
  30. bambamyi

    bambamyi

    Joined:
    Nov 26, 2008
    Posts:
    90
    Thanks for the quick reply! One more stupid question for ya Prime. I see following message on the console... but plugin seems to be working.

    SendMessage: object SocialNetworkingManager not found!

    I must be doing something wrong :D
     
  31. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @bambamyi, add a SocialNetworkingManager prefab to your initial loading scene to get rid of the error.
     
  32. bambamyi

    bambamyi

    Joined:
    Nov 26, 2008
    Posts:
    90
    ah ok thanks alot :D
     
  33. hencz

    hencz

    Joined:
    Aug 19, 2010
    Posts:
    86
    Hi Prime31,

    Would you mind adding a new method to FacebookBinding:
    postMessage( Hashtable options ) that works just like showPostMessageDialogWithOptions( Hashtable options ).
    Without the dialog. Thanks

    Regards
    -Tibor Hencz
     
  34. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @hencz, you can use the REST or Graph API to post messages.
     
  35. hencz

    hencz

    Joined:
    Aug 19, 2010
    Posts:
    86
    oh thanks
     
  36. Vedad

    Vedad

    Joined:
    Sep 29, 2011
    Posts:
    29
    Hey guys,

    I feel like an idiot for having to ask this regarding an issue I'm having. I've integrated all the pieces as far as I can tell from looking at the video and reading the documentation. My iOS app will open up a Safari page with the Facebook App I've registered and ask for permissions from the user. Now, whether the user clicks "Allow" or "Don't Allow", the Safari page will start to do it's loading animation, and a pop up will appear that says "Safari cannot open the page because the address is invalid." I feel like it's a super small step that I overlooked or did wrong. But, I have spent the last 3 hours looking through my code to make sure everything is right, and I just can't seem to pinpoint where the problem is.

    Anybody have any ideas regarding what I might have missed or done wrong? Thank you so much in advance.

    Vedad Dedajic
     
  37. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @Vedad, your Info.plist has not been setup correctly. Follow the instructions in the docs/video, delete the app from your device then rebuild it.
     
  38. Quickfingers

    Quickfingers

    Joined:
    Aug 29, 2009
    Posts:
    268
    hey mike, I'm having a weird issue with the facebook plugin. I'm just trying the test scene with my app id in place and when I click login it loads the facebook application on my phone and then wait a moment then switches back to my app, and says login failed. Is this a known issue or have I just done something stupid? Cheers :)
     
  39. Quickfingers

    Quickfingers

    Joined:
    Aug 29, 2009
    Posts:
    268
    turns out its the facebook app was an old version. Updating it to 3.5 fixed the problem
     
  40. Vedad

    Vedad

    Joined:
    Sep 29, 2011
    Posts:
    29
    Prime,

    The app is using different .plists based on what we build for. My stupid mistake was that I didn't check to see that every one of them was changed with the drop down menu option in Unity. Thanks again, and great work with everything you've done!

    Vedad Dedajic
     
  41. ThanNewell

    ThanNewell

    Joined:
    May 4, 2011
    Posts:
    9
  42. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @ThanNewell, you can already do all that using the Graph API on the Facebook side and the graphRequest on the plugin side. The rest is all HTML/CSS/JS so you will need to show that in a web view. Facebook doesn't have native versions of that stuff yet.
     
  43. donlien

    donlien

    Joined:
    Apr 13, 2009
    Posts:
    229
    Hi, Prime31,

    I am studying Cocos2D now.

    I wonder does the plugins all you made can support Cocos2D?
     
  44. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @donlien, they would all work. Of course you wouldn't need the Unity scripts though. You would only need the C/Obj-C files.
     
  45. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    Hi, I'm having some troubles with the facebook and twitter plugin. For facebook, I get to the facebook login (using the new iPad app, but earlier today I didn't have it installed so was just using the web site). Then I get the "<game> is requesting optional permissions" window and I leave both of them checked (Post to facebook as me, Access my data any time). When I tap "allow all" I then get "An error occurred with <game>. Please try again later". It doesn't work in the sample either. From googling around I have a feeling this is a facebook problem, but just in case anyone has any thoughts I figured I'd post. It worked the first two times from my game, but now every subsequent time it hasn't worked even after deleting the app from the iPad and deleting the xcode directory and rebuilding everything (I'm going to try recreating the app in facebook to see if that makes a difference). I've tried using both FacebookBinding.login and FacebookBinding.loginWithRequestedPermissions with "publis_stream" and "offline_access".

    Also with twitter, I get the error "Twitter post failed: Could not authenticate with OAuth." however in the sample it actually does work. I've set up everything exactly the same though. I have a SocialNetworkingEventListener, a SocialNetworkingManager, I call init and pass in my consumer key and secret (exactly the same in my code as the sample - copied and pasted from my app to the sample in fact). I call showOauthLoginDialog and I can log in, and the console log I see "Successfully logged in to twitter" followed by the error above (could not authenticate..).

    Anyone got any ideas?
     
  46. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @sam, you are the second person I have heard in the last few hours with Facebook login problems. The issue definitely appears to be on their side because it is always either while in the Facebook app or on their website. It is quite odd that the demo works for you when posting to Twitter but in your app it does not. Did you double check that you have entered your Twitter details correctly in the init method? Just to be thorough, did you delete your game from your device before reinstalling?
     
  47. daveMiller1980

    daveMiller1980

    Joined:
    Jul 27, 2010
    Posts:
    8
    Hi Prime,

    I'm having issues with logging into facebook-
    The first time I login through my iOS app, I am redirected to the facebook website, where after entering my username password I am prompted to allow permissions for my app. Once Allowed, I am taken back to my iOS app, where I am able to post to facebook - All good working.

    However, once I log out, if I attempt to log in again I am redirected to the facebook website, where I am presented with a page which simply has a title bar that reads 'Permissions' an 'Okay' button. On pressing this button, I am given the following error:

    An error occurred with <MY_APP_NAME> Please try again later.
    API Error Code: 100
    API Error Desription: Invalid parameter
    Error Message: Requires valid redirect URI.


    Logging in also fails when I have the facebook app installed. (I am redirected to the facebook app momentarily before being returned to my iOS app, logging in fails. )

    Although, logging in to facebook succeeds on an iPhone3G with no multitasking, using the pop-up login dialog!

    I have deleted my app from my device before building again.

    Any ideas? :)


    P.S. I am currently using several of your plugins in my project, this is the first issue I have had with any of them, they're great have saved me an enormous amount of time!

    UPDATE - WORKAROUND FOUND:
    I have been able to get logging in working consistently by disabling Facebook’s new Enhanced Auth Dialog. ( Go to your app on the Facebook Developer website > Settings > Advanced > switchEnhanced Auth Dialog:to Disabled. )

    UPDATE- The above workaround seems to fix the issue with logging in via safari, but does not work for logging in via the latest version of the Facebook App ( 4.0.2 )

    UPDATE- The Facebook-App based logging in is now working for me :)
     
    Last edited: Oct 16, 2011
  48. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @daveMiller, you are the 3rd person with the same issue. It definitely appears to be something on the Facebook side of things. I will be opening a bug report with Facebook today.
     
  49. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    Thanks for the quick responses! I turned off "enhanced auth dialog" and now it's working (even when logging in via the facebook app).

    I deleted the app before installing, and I've copied/pasted the exact same details into the sample and my code. I'll dig deeper - it must be something I'm doing wrong since the sample works. Thanks!
     
  50. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    Hmm, it seems to be working now, after deleting the ios directory under my unity project and rebuilding :/

    I have another question though, but it's not directly related to the social networking plugin. I'd like to use the postImage method. How do I get an image into the bundle or documents directory in Unity? Thanks in advance.