How to Programmatically Log Out from Facebook Sdk 3.0 Without Using Facebook Login/Logout Button

How to programmatically log out from Facebook SDK 3.0 without using Facebook login/logout button?

Update for latest SDK:

Now @zeuter's answer is correct for Facebook SDK v4.7+:

LoginManager.getInstance().logOut();

Original answer:

Please do not use SessionTracker. It is an internal (package private) class, and is not meant to be consumed as part of the public API. As such, its API may change at any time without any backwards compatibility guarantees. You should be able to get rid of all instances of SessionTracker in your code, and just use the active session instead.

To answer your question, if you don't want to keep any session data, simply call closeAndClearTokenInformation when your app closes.

Facebook SDK 4 for Android - how to log out programmatically

You can use LoginManager.getInstance().logOut();, even if you use LoginButton because

This UI element wraps functionality available in the LoginManager.

EDIT:
Just to mention that this works for Facebook SDK v4. I don't know if they will change it in the future.

@as batoutofhell mention, don't forget to put FacebookSdk.sdkInitialize(getApplicationContext()); to initialize the facebook sdk. Please see here for the details.

How to programmatically logout from facebook SDK 4.7 without using facebook logout button?

Call the following code whenever you want to logout programmatically.

LoginManager.getInstance().logOut();

How to Logout from Facebook and switch a user?

Change your FacebookLogin function to a coroutine function. By doing this, you can check if the user is logged in, log the user out then wait every frame until FB.IsLoggedIn is false before you can login another user. Also add a timer to the wait so that when FB.IsLoggedIn is never false within x amount of time, the function won't continue to run but show some error and exit.

public IEnumerator FacebookLogin()
{
//5 seconds loggout time
float waitTimeOut = 5f;

//Log out if loggedin
if (FB.IsLoggedIn)
FB.LogOut(); //it doesn't work, user is still logged in

//Wait until logout is done. Also add a timeout to the wait so that it doesnt wait forever
float timer = 0;
while (FB.IsLoggedIn)
{
if (timer > waitTimeOut)
{
Debug.LogError("Failed to log out within " + waitTimeOut + " seconds");
yield break;
}
timer += Time.deltaTime;
yield return null;
}
Debug.Log("Successfully logged out. Now logging another user in");
var permissions = new List<string>() { "email" };
FB.LogInWithReadPermissions(permissions); //trying
}

If you still have issue with this, you need to file for a bug report on the facebook-sdk-for-unity Github page with the code in this answer.

Logout Facebook Android SDK

Can you use closeAndClearTokenInformation() as described here: https://developers.facebook.com/docs/reference/android/current/class/Session/ ?

See also How to programmatically log out from Facebook SDK 3.0 without using Facebook login/logout button?

Facebook SDK WebView doesn't logout

I've solved by using this line on my LoginButton:

    facebookLoginButton.setLoginBehavior(LoginBehavior.WEB_VIEW_ONLY);

This forces the sdk to use a custom webview (which is different from web_only, that opens the default browser's view).

Than I can use the code of the question to logout at the end of the interaction.

Android Facebook 4.0 Logout Programmatically

No. It is a common problem even with oauth type "signup via facebook or gmail", where even if you logout from the third party app, you dont get out of fb or google. There is no mechanism which can make your app issue logout command to facebook app.



Related Topics



Leave a reply



Submit