6


I'm developing a game for Android that has Facebook login and I faced the following weird behaviour when trying to logout:
if user press Facebook logout button, closes the app and then reopens again, the user is still logged in (= access token still valid). As a test, I checked the access token after logout and it is null as it should be, but if I close and reopen the app then the access token is again not null.
It seems that Facebook caches the access token and takes it from cache even after logout.

I tried using native Facebook button and also LoginManager.getInstance.logout(); I have initialized Facebook sdk on the top of the onCreate, before setContent() and I followed the procedure on Facebook docs, but same result.

I'm using Facebook sdk 4.6.0 and I faced this problem on Android 4.2.2 and 4.4.2.

EDIT

Here's the code:

- Facebook button:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    setContentView(R.layout.activity_settings);
    btnFacebookLogout.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {

        }

        @Override
        public void onCancel() {
        }

        @Override
        public void onError(FacebookException e) {

        }
    });
}



- normal button:

btnNormalLogout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            LoginManager.getInstance().logOut();
        }
    });

Any suggestion?

Thanks in advance

5
  • Include your code so we can help?
    – Shawn
    Commented Dec 8, 2015 at 18:36
  • Yeah, sorry. I added code in the edit. Thanks Commented Dec 9, 2015 at 8:34
  • Try to set the access token to null yourself in the callback and see if that helps?
    – ifaour
    Commented Dec 18, 2015 at 12:26
  • do you mean inside onSuccess? Commented Dec 18, 2015 at 14:14
  • Can you please tell me how you solved it?
    – Atheer
    Commented Dec 17, 2021 at 12:28

1 Answer 1

6

Well, i`ve been fighting that damn sdk for about an hour and discovered a simple workaround for that logout issue.

Just try to do the following: LoginManager.getInstance().setLoginBehavior(LoginBehavior.WEB_ONLY)

Pros: LoginManager.getInstance().logOut() works fine in this case.

Cons: the authentication will always appear in a webview dialog.

3
  • Worked for me !! Commented Oct 11, 2017 at 11:15
  • 2
    thank for your suggest but in my case i use this LoginManager.getInstance().setLoginBehavior(LoginBehavior.WEB_VIEW_ONLY);
    – vuhung3990
    Commented Oct 12, 2017 at 7:28
  • it doesn't work for me, I still have the same issue
    – Atheer
    Commented Dec 17, 2021 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.