Kristupas A.
Kristupas A.

Reputation: 344

Facebook Android SDK getting cached access token

I need to check if access token exists at some point in the APP's lifecycle. How would I retrieve a cached access token in Facebook Android SDK?

Upvotes: 0

Views: 689

Answers (2)

kassim
kassim

Reputation: 4009

AccessToken accessToken = AccessToken.getCurrentAccessToken();

In the latest version of the SDK

Upvotes: 0

Shirwa Mohamed
Shirwa Mohamed

Reputation: 191

In this case, you should use SharedPreferences. What you would do is commit the token to the user's SharedPreference after you recieve it from Facebook, and then you can check it throughout your app whenever you need it.

Storing the Token

  SharedPreferences sharedPref = yourActivity.getPreferences(Context.MODE_PRIVATE);
  SharedPreferences.Editor editor = sharedPref.edit();
  editor.putString("user_token", theUsersToken);
  editor.commit();

Retrieving the token.

String token = sharedPref.getString("user_token", "empty");
if(token.equals("empty"))
  //user is not logged in..

Upvotes: 2

Related Questions