Access token removed in Facebook Android SDK 4.0

13,739

Solution 1

you can get access_token by using loginResult.getAccessToken().getToken(); as following code

 LoginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {

          String accessToken= loginResult.getAccessToken().getToken();

        }

Solution 2

By default the SDK will not log access tokens to logcat (this is to avoid leaking user tokens via the log).

You can, however, enable in debug mode a logging behavior to log the access token. Just add this when you're calling FacebookSdk.sdkInitialize(), but make sure to only do it when you're in debug mode:

if (BuildConfig.DEBUG) {
    FacebookSdk.setIsDebugEnabled(true);
    FacebookSdk.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
}

Solution 3

You can get the token by using

 AccessToken.getCurrentAccessToken().getToken()

Using this you can get the token at any time, if you use the LoginResult, you get it only once at the time you log in, when you restart the app the onSuccess is not called.

If you need the profile after restarting, you use

Profile.getCurrentProfile();

If this returns null you are not loged in

Share:
13,739
Che
Author by

Che

Updated on July 21, 2022

Comments

  • Che
    Che almost 2 years

    I am using Facebook Android SDK 4.0 (newly updated version). I logged in to my app after the initial setup. Then I exited from my app. If again start my app, user is not in the logged in state. When I use debugger, it shows "ACCESS TOKEN REMOVED". What is the procedure to check whether the user is in logged in state using Access Token?

    I have tried new log in method (according to newer version 4.0) in which they mentioned about log in process. I have done it. But whenever I open up Access Token state is "ACCESS TOKEN REMOVED". I checked App id, Package name, Activity name in dash board settings. All are correct. Help me to find solution for this problem.