35

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.

kumar
  • 359
  • 1
  • 3
  • 3

12 Answers12

51

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.

Karim Varela
  • 7,562
  • 10
  • 53
  • 78
  • I am not sure, but will not be hash created when exporting the package different? If it will, then facebook will not work with your app as the hash generated with your code is different – erdomester Aug 04 '13 at 21:06
  • 6
    This work, but you can also use **getPackageName()** instead of **""**, so you do not have to worry if you change the package name or something like that. – Sabo Sep 07 '13 at 11:12
  • I used the method in this answer to create that hash and then solved my problem using Matt's troubleshooting #2 - I did step #5 from the facebook guide - https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/. – bentzy Dec 10 '13 at 09:38
7

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:

  1. You have entered incorrect credentials in the Facebook native app itself.

  2. 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.

Matt Accola
  • 4,090
  • 4
  • 28
  • 37
5

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;
    }
}
Christopher Masser
  • 809
  • 13
  • 25
5

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"
dtbarne
  • 8,110
  • 5
  • 43
  • 49
  • Without your answer, I could have spent further 7-8 hour. Thaaanks very much!! – Hamzeh Soboh Sep 08 '14 at 13:02
  • I want to add a new line for this answer. If you do not have this launchMode, be sure not to have "android:noHistory="true"" in your manifest for your activity element. – alicanbatur Nov 05 '14 at 09:00
3

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.

Sabo
  • 1,635
  • 1
  • 19
  • 24
2

Try uninstalling your facebook app from your device, then reinstalling.

Karim Varela
  • 7,562
  • 10
  • 53
  • 78
  • Interesting. I'm having the same problem and after uninstalling the facebook app, the authentication works. I've filed a bug on developer.facebook.com for this, fyi: https://developers.facebook.com/bugs/322632771172055?browse=search_510fe419ecf076e37077278 – Karim Varela Feb 04 '13 at 16:40
2

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"

Community
  • 1
  • 1
Chris Sim
  • 4,054
  • 4
  • 29
  • 36
2

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);

Source: Android - Force Facebook connexion - Stack Overflow

Community
  • 1
  • 1
John Smith
  • 96
  • 9
0

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.

how to sign your project

how to extract key hash

loshkin
  • 1,600
  • 2
  • 21
  • 38
0

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 !!

Ahmed Adel Ismail
  • 2,168
  • 16
  • 23
0

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.

Chris
  • 31
  • 1
-1

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.

Jeff of Brooklyn
  • 307
  • 6
  • 19