4

I've managed to successfully log in FB using FB.Login function. Now I want to log out:

FB.Logout();
Debug.Log("FB IS LOGGED IN " + FB.IsLoggedIn);

I am expecting the above code to print the value of FB.IsLoggedIn as false and to ask me for a login and password on the next FB.Login.

In fact the value of FB.IsLoggedIn is true and I am not being logged out: next call to FB.Login does not ask for password and I am not being logged out when I open facebook site in my browser.

I've also tried to use the undocumented request to https://www.facebook.com/logout.php?next=[YourAppURL]&access_token=[ValidAccessToken] but it didn't make any effect for me.

How can I log the user out of facebook in my standalone unity application?

In fact what I need is to log in with different login and password.

Maybe I can invalidate the access token somehow which will cause the FB to ask me for login and password again?

Any help is much appreciated.

SDK version: 5.0.1

Build version: 140401.725cc2ecbc9002a

Unity Version 4.3.3f1 (c8ca9b6b9936)

Kolyunya
  • 5,973
  • 7
  • 46
  • 81
  • You can make your own logout callback. You can view [this](http://stackoverflow.com/questions/26746639/unable-to-logout-of-facebook-within-unity-ios/26839400#26839400) – Hamza Hasan Nov 10 '14 at 09:36
  • the above comment doesn't help at all. That question just points back to this question.. – silentkratos Aug 10 '15 at 01:39

3 Answers3

0

I believe the FB.Logout operation is asynchronous, and the value of FB.IsLoggedIn would be true immediately after calling FB.Logout(). If you look at the documentation, it says:

You almost certainly should not use this function, which is provided primarily for completeness. Having a logout control inside a game that executes a Facebook-wide logout will violate users' expectations. Instead, allow users to control their logged-in status on Facebook itself.

wheelsx
  • 186
  • 4
  • 1
    Each asynchronous function has (normally) a callback which logout doesn't have. Why do you think it is asynchronous? I've waited a minute after logout - nothing happened. – Kolyunya Apr 24 '14 at 05:21
  • I figured it was asynchronous simply because every other facebook function that communicates with the server is, I just can't see it being any other way. Other than facebook saying it probably shouldn't be used in apps (except, obviously, if the user is intending to log out of facebook altoghether), I don't know much about that one. Are you testing it just in the editor? Facebook says the version in the Unity editor has very few features, it's best to test it on an actual device. – wheelsx Apr 25 '14 at 04:32
  • 1
    I was testing it on the actual device. I have no alternatives but logout. I need to allow user to log in my application using different FB accounts. – Kolyunya Apr 25 '14 at 17:02
  • 1
    That comment is really only for Web. The documentation has since been updated and that sentence now starts with "On Web,". – Ted Bigham Feb 24 '17 at 00:07
0

Actually FB.Logout() has no delegate to let you know that account is successfully logout, so you have to create your own listner.

Secondly it will not sign you out from the actual device Facebook app or browser. If you want to sign in with different account, so you can do by signing out explicitly from the app or browser.

Here is the code for how to detect that if you are logged out. It may useful to show Login and Logout button for Facebook that when to Login or Logout.

Here is the code from that you can determine the user has logged out within the Game.

public void OnFacebookLogout()
{
    if (FB.IsLoggedIn)
    {                                                                                  
        FB.Logout (); 
        StartCoroutine ("CheckForSuccussfulLogout");
    } 
}

IEnumerator CheckForSuccussfulLogout()
{
    if (FB.IsLoggedIn) 
    {
        yield return new WaitForSeconds (0.1f);
        StartCoroutine ("CheckForSuccussfulLogout");
    } else 
    {
    // Here you have successfully logged out.
    // Do whatever you want as I do, I just enabled Login Button and Disabled
    // logout button through this method.
        EnableFacebookLoginButton ();
    }
}
Hamza Hasan
  • 1,368
  • 9
  • 17
  • FYI: merged from http://stackoverflow.com/questions/26746639/unable-to-logout-of-facebook-within-unity-ios – Shog9 Nov 12 '14 at 02:27
0

I'm not sure if it is correct but why not just do some while loop?

IEnumerator FBLogout (){
 FB.Logout ();
 while (FB.IsLoggedIn){
  print ("Logging Out");
  yield return null;
 }
 print ("Logout Successful");
}
vfxjex
  • 1