Amokrane Chentir
Amokrane Chentir

Reputation: 30385

Facebook API's method: isSessionValid() always returns true

I am using the official facebook SDK for Android and I am facing some issues regarding session management. Specifically, I don't know how to test whether the session is still valid or not.

First I initialize and authorize a connexion to facebook:

Facebook facebook = new Facebook(context.getString(R.string.facebook_app_id));
facebook.authorize(...); // Works ok

Then, I want to disconnect the user:

facebook.logout(context);

But once I have done that, the following still returns true:

facebook.isSessionValid();

Why does it return true?

Anything I'm doing wrong?

Thanks!

Upvotes: 0

Views: 2888

Answers (2)

Liquid_Mittens
Liquid_Mittens

Reputation: 76

Im not sure how you integrated facebook in your app but are you checking the access token from the shared preferences? If you are I would check to see that you are actually setting the new access token. For example, after the log out you would want to write out that new access token (null) so next time it would prompt the user to log in again.

Upvotes: 2

user658042
user658042

Reputation:

Maybe you encountered an older bug. Is your Facebook SDK up to date?

According to the source, logout calls setAccessToken(null);. And if the token is null, isSessionValid() should return false. Here is it's code for reference:

public boolean isSessionValid() {
    return (getAccessToken() != null) &&
            ((getAccessExpires() == 0) ||
                    (System.currentTimeMillis() < getAccessExpires()));
}

The getter/setter doesn't do any null-checks either, so the call in logout() should have the desired effect.

Upvotes: 2

Related Questions