Popescu Denisa Elena Popescu Denisa Elena - 2 months ago 14
Android Question

AccessToken.getCurrentAccessToken() is null

I Integrated facebook in my app and getting the proper token. If the token already exists then it assigns it, and if its the first time then it will make a request for the token. However, the token is not being received.

Here is my code:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(this.getApplicationContext());
callbackManager = CallbackManager.Factory.create();

accessTokenTracker = new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(
AccessToken oldAccessToken,
AccessToken currentAccessToken) {
// Set the access token using
// currentAccessToken when it's loaded or set.
}
};
// If the access token is available already assign it.
accessToken = AccessToken.getCurrentAccessToken();
setContentView(R.layout.activity_signup);

Answer

It seems you're not seeing the access token in this block, just like the comment tells you to. I could be wrong, but is that the issue you're having?

    accessTokenTracker = new AccessTokenTracker() {
        @Override
        protected void onCurrentAccessTokenChanged(
                AccessToken oldAccessToken,
                AccessToken currentAccessToken) {
            // Set the access token using
            // currentAccessToken when it's loaded or set.
            accessToken = currentAccesstoken;

        }
    };