I\'m upgrading my use of the Facebook SDK to the latest version. The following code is prety much lifted line by line from Facebook\'s own examples, which can be found here: htt
If you want to log in with the user that is now logged in on the Facebook app and you still have a token valid for a previous user, you can detect the error and log out in your FacebookCallback like this:
@Override
public void onError(FacebookException e) {
if (e instanceof FacebookAuthorizationException) {
if (AccessToken.getCurrentAccessToken() != null) {
LoginManager.getInstance().logOut();
}
}
}
Then you can log in again using the LoginManager.
if(LoginManager.getInstance()!=null){
LoginManager.getInstance().logOut();
}
Write before "registerCallback();" method
A lot of thanks to @sorianiv and @ming-li for their answers! I want to describe my case with more details because it can be helpful for somebody.
The Facebook SDK creates a shared preferences file called "com.facebook.AccessTokenManager.SharedPreferences". And when user signs in with facebook SDK stores access token, user name and other token info there. My issue was that I didn't call
LoginManager.getInstance().logOut()
when user signes out in my app. And the cache in shared preferences was not cleared. So when user than tries to sign in with different Facebook user Facebook SDK got the user data from the cache and returned error:
"User logged in as different Facebook user.”
In my case the solution was just to call logOut() when user signs out from my app.
You would get this error if you already have a valid access token, but are requesting additional permissions (via the LoginManager.logInWithReadPermissions call), and the user logged into the FB app is different from the one you already have an access token for. You can do a couple of things:
I also faced the same problem today. I got surpassed the problem by using below line of code when user clicks on FbLoginButton
LoginManager.getInstance().logOut();