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
    @ydder, Facebooks SDK decides if and when native auth is used.


    @tano, if you check if the session is valid after the login succeeded event fires it will be true.
     
  2. nah0y

    nah0y

    Joined:
    Apr 4, 2011
    Posts:
    74
    But I still never have the native login dialog...
    I've never seen anywhere that FB decides if and when native auth is used, they're juste saying that if you have the app + FB set up in the settings on iOS 6, it will open it.

    I've read the doc here https://developers.facebook.com/docs/howtos/ios-6/#nativeauthdialog but it's still not working.
    Digging through your code though, you are calling facebookSession openWithCompletionHandler instead of openActiveSessionWithReadPermissions, is it normal ?
     
  3. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @nah0y, read Facebooks documentation for the details of how their system works. I believe if you logged into the app without the native dialog at some point you will not get the native dialog on subsequent attempts. There are many different methods to open a session with the new SDK all of which internal to their SDK will take the same path.
     
  4. nah0y

    nah0y

    Joined:
    Apr 4, 2011
    Posts:
    74
    As I told you, I've read the documentation and it's written nowhere that they may or may not display it...
    And it's kind of incredible and hard to believe that they chose to sometimes display it or not, that's just really weird and absolutely not user friendly.

    For example, in Diamond Dash, I have the Native Dialog that popup right away, but not in my game. And I'm sure there is nothing different to configure on dev.facebook.com, so that must come from the code...
     
  5. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @nah0y, you will have to take it up with Facebook. We do non control how their SDK works.
     
  6. nah0y

    nah0y

    Joined:
    Apr 4, 2011
    Posts:
    74
    So how do you explain that it's working in Diamond Dash ? You think they allow only some app to use it ?
    I'd really love to see the page where it's written because I couldn't find it :(
     
  7. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @nah0y, it works fine in all of our test apps. Create yourself a new app and run it on an iOS 6 device with a FB account on it and it should work.
     
  8. e5an

    e5an

    Joined:
    Jul 6, 2012
    Posts:
    93
    How do I log into Facebook without requesting any permissions at all beyond the default set?
    I just got rejected by the App Store and I believe it is because of this:

    if (!FacebookBinding.isSessionValid())
    {
    var permissions : String[] = [ "email" ];
    FacebookBinding.loginWithRequestedReadPermissions( permissions );
    }
    }

    Can "permissions" be an empty array and that will still work? If so, you should advise people to do it that way instead of asking for email or birthday, both of which Apple specifically mention as not being OK to ask for without good reason to.
     
  9. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @kilo, you cannot login without any permissions. Read Facebooks documentation. They require one of three permissions to be requested at login time. If you pass an empty array the plugin will add the email permission automatically.
     
  10. nah0y

    nah0y

    Joined:
    Apr 4, 2011
    Posts:
    74
    I've just done that, new Unity project, new Facebook App, everything is working except the Native Login Dialog :(
    Could you send me one of your test app so I can test it ?
     
  11. ydder

    ydder

    Joined:
    Aug 3, 2012
    Posts:
    3
    Hi Prime.

    I want to stop the user from fast app switching.. Only if he is logged in the device I just want to the native auth dialogs to take care of the permissions. Essentially I do not want to use fast app switching instead i can display an alert saying user to log in. How can I do this. Thanks for your help.
     
  12. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @nah0y, it would be of no use to you. It is tied to my bundle IDs.


    @ydde, Facebooks SDK decides how authentication occurs internally.
     
  13. nah0y

    nah0y

    Joined:
    Apr 4, 2011
    Posts:
    74
    yeah... you're using the same basic code you have in the example included with the plugin ?
     
  14. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @nah0y, bone stock using the demo scene
     
  15. nah0y

    nah0y

    Joined:
    Apr 4, 2011
    Posts:
    74
    So i'm doomed lol...
    I can't even contact Facebook because I can't explain how your code works to call the authentification methods...
     
  16. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @nah0y, just copy/paste the login method and that will be all they need
     
  17. nah0y

    nah0y

    Joined:
    Apr 4, 2011
    Posts:
    74
    thx i'll try that !
     
  18. galgantur

    galgantur

    Joined:
    Nov 30, 2009
    Posts:
    5
    hi Prime 31
    Got problems during login (both iOs and Android).

    Code (csharp):
    1.  
    2.  
    3. FacebookManager.facebookReauthorizationWithPublishPermissionsSucceededEvent += OnReauthorizeSuccess;
    4. FacebookManager.facebookReauthorizationWithPublishPermissionsFailedEvent    += OnReauthorizeFailed;
    5. FacebookManager.loginSucceededEvent  += OnEventFacebookLogin;
    6. FacebookManager.loginFailedEvent     += OnFailedFacebookLogin;
    7. FacebookManager.dialogCompletedEvent += OnDialogCompletedEvent;
    8. FacebookManager.dialogFailedEvent    += OnDialogFailedEvent;
    9. FacebookAccess.init( "0123456789101112" );
    10.  
    11. if (!FacebookAccess.isSessionValid())
    12. {
    13.      Debug.Log("---------------------loginWithRequestedPermissions");
    14.      //login to FB
    15. #if UNITY_ANDROID
    16.     FacebookAccess.loginWithRequestedPermissions( new string[] { "publish_stream", "email"});
    17. #elif UNITY_IPHONE
    18.     var permissions = new string[] { "email"};//NOT deprecated
    19.     FacebookAccess.loginWithRequestedReadPermissions( permissions );//NOT deprecated
    20. #endif
    21.     //GameResources.CanDrawButtonPezza = true;
    22. }
    23. else
    24. {
    25.        //login to FB
    26.        Debug.Log("---------------------already logged");
    27.     OnEventFacebookLogin();
    28. }
    What happens:
    open app
    non valid session
    ask for login
    enter login (username and pass) for FB
    got struck in FB window
    get back to the game manually
    session still non valid
    ask again for login
    window says login is correct
    press ok
    back to the game
    then i can publish on wall

    looks like the event FacebookManager.loginSucceededEvent += OnEventFacebookLogin; is never thrown.
    work beacuse I test the session manually and I call the OnEventFacebookLogin manually.
    Did I miss something in my code? Looks quite simple.
     
  19. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @galgantur, if FB does not reopen your app you did not setup your Facebook or game properly and you will not be able to authenticate a user properly. Review the documentation and follow all the required setup steps.
     
  20. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    Alright, I just pushed out an update with a new method. Read and understand how Facebook authentication works before using it!

    - setSessionLoginBehavior method for full control over how Facebook authenticates a user. Understand what the login behaviors are and how they work before using this!
     
  21. valkia

    valkia

    Joined:
    Jul 19, 2012
    Posts:
    7
    Hi prime,

    I have to post it again, last post didnt get attention.

    how do i detect if user has pressed cancel or share button on the popup Facebook dialog using the method showDialog. The reason that I am asking this is because I found dialogCompletedEvent was still fired when user even pressed Cancel button. Thanks.
     
  22. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @valkia, if they posted the dialogCompletedWithUrlEvent will fire.
     
  23. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    418
    I just got the social networking plugin and have been working on getting Facebook posting working. The odd thing is that I seem to be able to publish from within my game without getting publish permissions, ie: I didn't have to call this:

    var newPermissions = new string[] { "publish_actions", "publish_stream" };
    FacebookBinding.reauthorizeWithPublishPermissions( newPermissions, FacebookSessionDefaultAudience.OnlyMe );

    I logged in with the read permissions, using only the basic info and user_birthday, and then used:

    FacebookBinding.showFacebookComposer( "app test: ", string.Empty, "www.url.com" );

    And the FB ios6 dialog showed up and it successfully posted to my timeline. So my question is whether this is correct and it's okat to skip the whole publish permissions step, or is this just because I am the app developer so my facebook account accepts publish requests from my own app?

    -JJ
     
  24. Artial

    Artial

    Joined:
    Dec 27, 2008
    Posts:
    22
    Dear Mike, I just wanted to say that using the lastest build (with setSessionLoginBehavior) has enabled ios6 native controls back into my game, I don't event need to call setSessionLoginBehavior (I think you code uses UseSystemAccountIfPresent by default). Thanks also to nah0y for being pushy!
     
  25. galgantur

    galgantur

    Joined:
    Nov 30, 2009
    Posts:
    5
    Do I have to set up the Facebook application as "Native iOS App" and "Native Android App"? Can you link me a tutorial in your doc? I can't find it.
     
  26. nah0y

    nah0y

    Joined:
    Apr 4, 2011
    Posts:
    74
    I just saw your message, and I'm really excited lool,
    I'm testing right now to see if it's working !
     
  27. nah0y

    nah0y

    Joined:
    Apr 4, 2011
    Posts:
    74
    Well =(

    You're luck, me, I'm now constantly having :
    FB LOGIN FAILED : The operation couldn?t be completed. (com.facebook.sdk error 2.)


    Edit :
    Well, something seems weird.
    I've created a new fresh app to test it out with the example scene. The first time I clicked on login, I had the native facebook login popup !! But then I press "Don't Allow". And now every time I'm clicking on login, I have the log :
    FB LOGIN FAILED : The operation couldn?t be completed. (com.facebook.sdk error 2.)

    Weird no ?

    Edit 2 :
    I've deleted the app, reboot the phone, recreated the Xcode project from scratch, and now it seems to be working ! The first time I pressed "Don't Allow", it seems it sets a boolean to false in Settings -> Facebook and then there was an error each time I pressed login, I'm now using FacebookBinding.setSessionLoginBehavior(FacebookSessionLoginBehavior.UseSystemAccountIfPresent); and it seems to be working.
     
    Last edited: Nov 9, 2012
  28. nah0y

    nah0y

    Joined:
    Apr 4, 2011
    Posts:
    74
    Okay, here is my conclusion :
    It's seems impossible to use a method that open native dialog, or fall back to FB app or webview if Settings -> Facebook has app disabled.

    Using UseSystemAccountIfPresent OR Nothing set :
    Settings -> Facebook -> App Enabled -- NATIVE DIALOG \o/
    Settings -> Facebook -> App NOT Enabled -- CONSTANTLY GETTING ERROR, and NO fallback to webview or anything else

    Using WithFallbackToWebView :
    Settings -> Facebook -> App Enabled -- WORKING (opening FB app) but NO native dialog
    Settings -> Facebook -> App NOT Enabled -- WORKING (opening FB app) but NO native dialog

    Using WithNoFallbackToWebView :
    Settings -> Facebook -> App Enabled -- WORKING (opening FB app) but NO native dialog
    Settings -> Facebook -> App NOT Enabled -- WORKING (opening FB app) but NO native dialog
     
    Last edited: Nov 9, 2012
  29. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @capital, the Facebook composer does not even require logging in. That is handled entirely by the iOS Facebook account setup in Settings.app.


    @galgantur, refer to Facebooks documentation to learn how to setup an app on their website.


    @nah0y, you should send that all over to Facebook so they can add it to their documentation.
     
  30. nah0y

    nah0y

    Joined:
    Apr 4, 2011
    Posts:
    74
    @prime31 i'm filling a bug report right now (but the website seems to be not working...)

    But if the app is not enabled, that might be the correct behavior... I mean, if the user has disabled the app on the settings, then it will fail, but I think they should at least tell the user something or show him back the login popup !
    We'll see...
     
  31. SolaninMoon

    SolaninMoon

    Joined:
    Nov 8, 2012
    Posts:
    6
    Hello
    I can not speak English well. Use Google Translate.
    During the Prime31 using the Android plug-in, there's a problem.
    Facebook Login -> Facebook log out -> exit the application -> application again to turn on -> Facebook login.

    After Facebook login id, login automatically without entering a password.
    Original login window will appear

    Is there a way to fix?
     
  32. TheDoc

    TheDoc

    Joined:
    Oct 23, 2012
    Posts:
    2
    For Facebook plugin, is it testable from within the Unity preview mode?
     
  33. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @doc, plugins are native code and will only run on an actual device running iOS.
     
  34. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    418
    Yeah, I noticed that after some testing on iOS 6, but then I tried it on an iOS 5 device that doesn't have facebook in settings app and it still only required read permissions.

    On iOS 6 using the composer it said that the message was posted from "iOS" instead of my game, but on iOS 5 using the below code, it said that the message was posted from my game, and didn't require publish permissions :)

    FacebookBinding.showDialog( "stream.publish", parameters );
     
  35. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @capital, dialogs do not require publish permissions. The user is doing the publishing with them.
     
  36. Kyhov

    Kyhov

    Joined:
    Sep 25, 2012
    Posts:
    8
    hi prime.
    i need your help, because i can not get my game score value from facebook!
    i tried research in facebook api graph explore ready, and by away the method in
    Facebook.cs
    public void getScores( string userId, Action<string, object> onComplete )
    {
    var path = userId + "/scores";
    get( path, onComplete );
    }


    so i don't know how to use this method for get score and assign to local variable in my script!


    thanks you first!
     
  37. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @kyhov, you just pass in a userId and completion handler. There isn't anything more needed. See the demo scene for an example.
     
  38. Kyhov

    Kyhov

    Joined:
    Sep 25, 2012
    Posts:
    8
    i passed the userId and completion handler, but i want assign the score value to new variable like
    String scoreValue = Facebook.instance.getScores( userId, completionHandler ) + "";


    but it doesn't work!
    can you write down the code for assign the facebook application score to variable in unity script!
     
    Last edited: Nov 12, 2012
  39. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @kyhov, visit Facebooks documentation to learn what Facebook will be returning to you when you retrieve the scores.
     
  40. appxplore-tech

    appxplore-tech

    Joined:
    Jul 4, 2012
    Posts:
    62
    Currently when I attach a delegate functions for the Facebook.instance.postImage / graphRequest there is a questions.
    When I attached a delegate function for it, it returns null for error even there is an error happens. Please assist.

    Thank you very much if you can answer this ASAP:)
     
  41. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @app, the error parameter will only occur when an error with the actual web request fails. A full-stop kind of error. You can still have Facebook errors returned via the object property which would indicate the web request finished properly but you messed up your Graph request.
     
  42. nah0y

    nah0y

    Joined:
    Apr 4, 2011
    Posts:
    74
    Hi prime,

    Is it possible to add a method to check if an app is authorized in Settings -> Facebook ?
    Because as I said, if it's not, we will always have an error returned, and not the FB app or the web view opened.

    So if we could check if the app is authorized, if it's not, we could force opening the webview or the FB app.
     
  43. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @nahoy, there is no method in the Facebook SDK to do that
     
  44. nah0y

    nah0y

    Joined:
    Apr 4, 2011
    Posts:
    74
    Okay, so basically, we're f****d or we must not use the native login...
     
  45. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @nah0y, I believe Facebooks thought process was that if the user disables Facebook for your application they don't want to use it so you should hide all FB related features. I can't speak for their design decisions but it makes sense to me as a user.
     
  46. nah0y

    nah0y

    Joined:
    Apr 4, 2011
    Posts:
    74
    Yes it totally makes sense, but let's say for some reason you've disabled it, if the user then decide to use it again, he won't remember that the app is disabled in the settings (that was my case)... and as a user, I would expect a choice to connect with facebook again...

    But i've created a bug report, I'll wait to see what's their answer.
     
  47. koki

    koki

    Joined:
    Nov 27, 2009
    Posts:
    43
    Hi prime31,

    I'm getting linking errors when compiling using the last version of the plugin. Here is the message:

    Code (csharp):
    1.  
    2. Undefined symbols for architecture armv7:
    3.   "__facebookSetSessionLoginBehavior", referenced from:
    4.       RegisterMonoModules() in RegisterMonoModules.o
    5. ld: symbol(s) not found for architecture armv7
    6. clang: error: linker command failed with exit code 1 (use -v to see invocation)
    7.  
    My Traget iOS version is set to 4.3 and SDK Version to the latest (6.0 or later). I'm compiling on Mountain Lion and Xcode 4.5.2.
     
  48. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @koki, looks like you didn't delete the old files before importing the latest update. Delete all SocialNetworking files from the editor directory, reimport plugin, rebuild and clean your Xcode project to wipe the object cache n
     
  49. SolaninMoon

    SolaninMoon

    Joined:
    Nov 8, 2012
    Posts:
    6
    Hello.

    During the Prime31 using the Android plug-in, there's a problem.
    Facebook Login -> Facebook log out -> exit the application -> application again to turn on -> Facebook login.

    After Facebook login id, account login automatically without entering a password.
    i want login window.
    how can i do it?
     
  50. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @solanin, report that to Facebook. There is nothing we can do to assist. Their SDK caches credentials.