Always getting Session state:CLOSED_LOGIN_FAILED, token:{AccessToken token:ACCESS_TOKEN_REMOVED in facebook android sdk3.0. Even when i run the examples given by the facebook sdk its authenticating and not redirecting it to next flow.it displays the previous page itself.
For some reason, the hash that the keytool is generating for me isn’t the same as my app. This is what worked for me. Generate a hash using the standard code provided by facebook:
PackageInfo info = getPackageManager().getPackageInfo("<your_package_name>", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures)
{
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
Make sure to replace “your_package_name>” with your corresponding package name. Look at logcat and grab the keyhash and enter it in your facebook app settings.
###
The ACCESS_TOKEN_REMOVED has nothing to do with the problem. This is simply the Facebook SDK not logging the access token. So you can safely ignore that part of the error.
There are two things that are probable causes of the CLOSED_LOGIN_FAILED:
-
You have entered incorrect credentials in the Facebook native app itself.
-
The Android key hash entered in your app settings on developers.facebook.com does not match the key hash of the APK.
To troubleshoot #1 Open the Facebook native app and make sure you are logged in properly and can access content. If you have incorrect credentials entered in the Facebook native app (perhaps you recently changed your password) then the Facebook SDK will repeatedly try to do an SSO using the native app and report back CLOSED_LOGIN_FAILED.
To troubleshoot #2 Just follow the instructions under “Create a Facebook App” on this page, https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/.
The examples provided with the Facebook SDK will fail because the app configuration for the sample apps will not have your debug key hash registered. There are instructions for how to fix this under “Run the Samples” in the same link. Here’s a quote:
Put simply, every Android app you’ll create will be signed, and you
will need to register each app’s key hash with Facebook as a security
check for authenticity – as we’ll see later. But to bypass this check
for the SDK samples and to get them up and running quickly, you can
add your key hash to your global Facebook Developer profile.
###
I had a similar issue – I was getting CLOSED_LOGIN_FAILED
with com.facebook.FacebookOperationCanceledException: User canceled operation
and I definitely wasn’t canceling the operation.
After a good 7-8 hours of toying with every line of my application code, I noticed that this was set on my activity in my manifest. Removing it solved it.
android:launchMode="singleInstance"
###
I had the same error and I had forgotten the following line in onActivityResult of the starter activity:
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
Here is the whole method:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case RESULT_CODE_IMPORT_FACEBOOK:
//do stuff
break;
default:
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
break;
}
}
###
If you are using the Facebook application in the sandbox mode, make sure the account you are using is in the list of authorized admins or developers.
###
Try uninstalling your facebook app from your device, then reinstalling.
###
Another workaround is to supress the sso login method. This can be done like this:
LoginButton authButton = (LoginButton) view.findViewById(R.id.authButton);
authButton.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);
###
I faced the same problem but the solution was that I had to enter to facebook (developper.facebook) and in my apps settings and add the keys that If used and add the package name
If it doesn’t help you try to access this link for other solution:
“Android Facebook SDK 3.0 gives "remote_app_id does not match stored id" while logging in“
###
If you don’t sign your APP explicitly with a certain key store the IDE it will sign it for you with the default one. You have to sign your project with specific key store, extract the key-hash and add it to you Facebook account.
###
in my case, the Facebook application id was wrong, and also the Key Hash was not added to Application on facebook
strange enough it used to work fine on a debuggable non-signed version !!
###
We faced the same problem and was looking and googling around for a quite long time. I checked the hash key, manifest file and a lot of other things to fix this issue. We are using the older 3.23.1 version of the facebook sdk and our app was not able to connect to facebook, for certain phones only. It returned the “CLOSED_LOGIN_FAILED” state and via logcat it reported “Cannot call LoginActivity with a null calling package. This can occur if the launchMode of the caller is singleInstance”.
On some phones, like the ones from Fairphone, there is a new feature added:
https://fairphone.zendesk.com/hc/en-us/articles/207164396-What-is-the-Privacy-Impact-feature-
This feature avoids the reliable communication to facebook in some special circumstances. As soon as you untick it, start your app again and accept the permissions, our app was behaving like expected.
Hope this helps to avoid the grey hairs i got during fixing it.
###
I also got this error from the SessionLoginSample for hours. It worked after I created an explicit app, SessionLoginSample, at developer.facebook.com. I copied the app id into the Android manifest, etc. and it worked. In other words, the Sample App configuration described in Facebook’s Getting Started guide failed.