Prevent null accessToken while upgrading from the android Facebook SDK v2 to v4?
I have an app using the v2 Facebook Android SDK. We have a large active user install base, so protecting the upgrade experience is important. I've seen how to prevent the logout on iOS here and here - but not for Android..
To detect if a user is logged in, the docs say to do this:
AccessToken.getCurrentAccessToken() == null
...but the current access token is ALWAYS null on the first run after upgrading the app from the v2 version to the v4 version. This is probably because the storage location for the token has changed.
Even if I set FacebookSdk.setLegacyTokenUpgradeSupported(true); we still get null after upgrading our APK.
Is there a way to upgrade the facebook android SDK and maintain user's auth tokens so that they have a seamless upgrade experience?
You need to set FacebookSdk.setLegacyTokenUpgradeSupported(true); and ensure that you are properly using the LoginButton. We were missing some fragment related code - which broke the process.
After adding the legacy token flag and adding the missing .setFragment(this) call our legacy tokens worked.
I had this issue too but in my case I was forgetting to set the application id before calling initialize.
FacebookSdk.setApplicationId(fbAppId); FacebookSdk.setLegacyTokenUpgradeSupported(true); FacebookSdk.sdkInitialize(getApplicationContext());