90

I am getting this error. When I try to sign in with facebook to my app. When I first time authentication it will correctly working. After I unistalled my application and now trying to sign in with Facebook on that I am getting this error.

Another Issue : After authenticate in device1 and try to login with facebook on device2 also same error is getting.

Solution I Found : when I remove App authentication from Facebook App Settings it is working in above scenario's but this is not an good solution how we can tell to users to do this action?

btnFbLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(accessToken != null) {
                    boolean expires = accessToken.isExpired();
                    if(!expires) {
                        performFbLoginOrSignUp(accessToken);
                    }
                } else {
                    LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
                    callbackManager = CallbackManager.Factory.create();

                    if (loginButton != null) {
                        loginButton.setReadPermissions("public_profile", "email", "user_friends");

                        if (CommonUtil.isConnectingToInternet(LoginActivity.this)) {
                            loginButton.performClick();

                            loginButton.setPressed(true);

                            loginButton.invalidate();

                            loginButton.registerCallback(callbackManager, mCallBack);

                            loginButton.setPressed(false);

                            loginButton.invalidate();
                        } 
                    }
                }
            }
        });

Error page

In Facebook example also having an issue : GitHub link of Facebook example

Steps to reproduce :

  1. Launch the app Login with Facebook Authenticate FB profile.

  2. Un_install the app and install again.

  3. Now try to Login with Facebook.

  4. The above error will occur. because we already authenticated so need to access fb profile. but here we facing the issue.

  5. Here already authenticated page is not showing.

  6. I am using Native FB app with the device Xiaomi Redmi Note 3

7
  • 2
    This seems to be a bug with facebook SDK. Many developers facing the same issue since past few days developers.facebook.com/bugs/297086380683342 Aug 20, 2016 at 15:28
  • I'm getting this. Removing the app seems to work once, and then the error happens again. Aug 20, 2016 at 17:41
  • @Patrick , Yes removing app is fine. I already mentioned in my question. But this is not a permanent solution. We can't tell to user to remove in this scenario. Aug 22, 2016 at 4:48
  • 1
    same problem occurred in this morning my client is about to kick me out now.
    – Ram Mandal
    Aug 23, 2016 at 5:08
  • No still not solved. I attached screen cast in developers.facebook.com/bugs/297086380683342 Aug 25, 2016 at 7:22

21 Answers 21

86

The error occurs because of invalid hash key.

We can create Hash key using the below command and update the same here under Settings-> Basic -> Android HashKeys

keytool -exportcert -alias ADD_RELEASE_KEY_ALIASE_HERE -keystore ADD_UR_KEYSTORE_PATH_HERE | openssl sha1 -binary | openssl base64

You can find the Relase Key Alias of your keystore using the below command if needed:

keytool -list -keystore ADD_UR_KEYSTORE_PATH_HERE

I have also experience an issue like by using the above HashKey the login works fine if I install the release APK directly to the device, But when I upload the APK to Play Store and install app from store then it shows the same Login failed error. The fix for this is as follows:

  1. Go to Release Management here

  2. Select Release Management → App Signing

  3. You can see SHA1 key in hex format App signing certificate.

  4. Copy the SHA1 in hex format and convert it in to base64 format, you can use this link do that without the SHA1: part of the hex.

  5. Go to Facebook developer console and add the key (after convert to base 64) in the 

    settings → basic → key hashes

5
  • Mine issue is , it is working in some devices and not working in other devices (Samsung, Redmi). After putting key into developers console, app is crashing for specific devices (Samsung, Redmi)
    – jack_07
    Mar 9, 2020 at 20:34
  • 2
    My app is not released, it is still in under development. I am creating the release build and also create release Keystore and generate a sha1 hash key using release Keystore. But still I am not able to log in, if the Facebook app is installed, without facebook app from web login dialog its working. Please help me to solve it. @SumiSadic May 21, 2020 at 10:41
  • do i have to put my upload-keystore.jks file too in the app folder ? Oct 18, 2021 at 15:41
  • I have spent a few day to sloved this problem. This comment is very useful and I suggest this comment in github too. github.com/AntonioCuevaUrraco/nativescript-facebook-login/…. And try to run gradlew signingReport or ./gradlew signingReport at android root project and find something xx-release then compare SHA1 with above method in github you will understand when you see it. This might help you. ;) Dec 8, 2021 at 7:28
  • Thank you for this, it saved me! Note that you need to follow the steps of going to Release Management → App Signing only if you chose Google to handle app signing for you (which is anyways recommended).
    – Narcis
    May 4, 2022 at 20:31
68

ANSWER

Just throwing this out there for people still experiencing this issue. The hash I created through the keytool was somehow incorrect. I fixed it by doing the following:

If you already uploaded your app to the playstore and enabled "app signing by Google Play" there is a solution (at least this worked for me):

  1. Login into the Google Play Console
  2. Click on the app you want the hash from
  3. Now, open the navigation on the left hand side
  4. Under Release click Setup > App integrity Navigation drawer in the Google Play Console
  5. Under App signing certificate copy the SHA-1 certificate fingerprint
  6. Go to http://tomeko.net/online_tools/hex_to_base64.php
  7. Paste the SHA-1 in the first field
  8. Copy the text in input field under Output (base64)
  9. Now open developer.facebook.com/apps
  10. Navigate to the dashboard of your app (My Apps > Your App Name)
  11. On the left side navigate to Settings > Basic
  12. Paste the Base64 text here under Key Hashes enter image description here

That should fix the issue.


UPDATE

The steps above should still fully work.

But if you do not want to paste your key on that website, here is an alternative to step 6,7,8 below:

here's a oneliner Node.js command to do the same:

node -e 'console.log(Buffer.from(process.argv[1].split(":").map(hex => parseInt(hex, 16))).toString("base64"))' '5E:8F:16:06:2E:A3:CD:2C:4A:0D:54:78:76:BA:A6:F3:8C:AB:F6:25'

credits: mifi


4
  • Fixed this issue by following the steps you mentioned. Lot thanks, you saved my time :-) May 13, 2020 at 9:35
  • This one was the ONLY ANSWER to solve my problem. I'm executing EXACTLY the steps told in facebook getting started, but still failing. I have this problem for years, and still today, the only code that works is that hex to base64 site gives.
    – Otuyh
    Jun 9, 2020 at 20:44
  • Your answer solved My Issue with this stubborn Facebook Error Aug 25, 2020 at 17:24
  • Basically, if you upload aab to google play and sign by google play, the production signing key will be different with dev which use the keystone in your local build. So you need add to hash key: one for dev and one for production
    – Xin Meng
    Jan 11 at 15:56
38
+50

I also Face this problem .Update your key hash on Facebook

9
  • I am already updated key hash. For you after update key hash is the problem resolved? Aug 22, 2016 at 10:46
  • 2
    But for me not resolved. Check this link developers.facebook.com/bugs/297086380683342 Here so many members facing same issue. I provides steps to reproduce please follow the steps to reproduce. Aug 22, 2016 at 11:09
  • 1
    Which sdk version you are use Aug 22, 2016 at 11:17
  • Before :com.facebook.android:facebook-android-sdk:4.0.0 Now : com.facebook.android:facebook-android-sdk:4.14.1 In both SDK version having an issue Aug 22, 2016 at 11:24
  • 1
    I just commented on the bug linked by @Naveen above. "Did any of the other people experiencing this bug have to type in a password to get their debug key hash? I didn't have to on the Mac I was using when following the Facebook tutorial. Then I got home, and I looked up how to get the hash on Linux. I had to type in the password "android" this time, and after putting this key into the developer console on Facebook, I was able to use the log in/out feature correctly." Aug 24, 2016 at 1:04
10
  1. Generate .apk file
  2. open a terminal where .apk file exists
  3. to keep in your mind that you have to generate two separate SHA1 keys for release and debug. e-g just run following command with debug.apk and release.apk
  4. run keytool -list -printcert -jarfile yourapkname.apk
  5. you will get

MD5: 00:00:A0:00:00:00:72:00:00:B9:00:00:00:3D:00:00

SHA1: 00:00:94:00:67:00:FA:00:4E:00:CE:80:00:1A:00:00:00:00:00:00

SHA256: 00:00:00:34:00:00:00:00:00:00:00:00:00:00:00:00:56:00:F5:00:00:49:00:4A:00:00:00:00:00:00:00:00

  1. copy SHA1 open http://tomeko.net/online_tools/hex_to_base64.php
  2. past in Hex string your Key Hash will be in Output (base64)
  3. copy your Key Hash and add in your App setting on developers.facebook.com
2
  • 3
    Thanks @Rasheed Qureshi, tried all methods, but your method save me. Mar 19, 2021 at 3:29
  • 1
    Confirmed working in Nov 2022 -- I first generated this on my local computer but Facebook didn't like them. I used this method and fixed the issue right away! BOOYA.
    – Andy
    Nov 4, 2022 at 17:28
6

I resolved the same issue by replacing the key hash,

How to generate the key hash for release. Open Chrome browser console to convert a hex map key to base64

Copy SHA1 key from google play console.

> btoa('a1:43:d4:27:c8:04:rr:fr:2g:3b:tg:b5:et:c1:4a:1t:fr:f5:54:5f'.split(':').map(hc => String.fromCharCode(parseInt(hc, 16))).join(''))
< "g5fGIBgB6noFO9ur78BdEr73KG6="
1
  • all the other i have tried but didn't work for me. And finally after hours i reached to your solution, This works for me thanks @Sujeet Kumar Sep 1, 2022 at 9:59
6
  • Hello All, I face this issue from last 2 months..

finally I got the solution.

  • Follow the Steps and Say in last. "Hurrey"

     1. Complete all process of facebook integration in android.
     2. Create your ***Hashkey (SHA1 key)*** from android 
        - steps : Go to left of Android studio screen and double click on this selected option.
    

enter image description here

    3. Then select SHA1 key from *"debug"* or *"release"* Variant.
       - If you want to do in live app then use *"release"* Varient.
       - other wise use *"debug"* Variant's SHA1 Key.
    4. Then Open the following link: http://tomeko.net/online_tools/hex_to_base64.php and paste SHA1 key.

enter link description here

    5. Select Output(base64) key which has "=" sign in end of line.
    6. Open your `Developer Facebook` site and Select Integrated App 
       then Go to -> Settings -> Basic -> Key hashes. Add these new key here. 

enter image description here

     7. Done Keep Code.
4

This is the issue from Facebook. Confirmed by Facebook Team.

enter image description here

We will Expected Resolution: within 3 days

2
  • Are you sure about this? Is this issue resolved now?
    – Ganesh AB
    Nov 30, 2017 at 7:46
  • Yes it was resolved on that instance. But not sure about now. If you having any issue raise the bug in developers.facebook.com/bugs Nov 30, 2017 at 7:58
3
  1. Remove app from user settings in Facebook (account).

  2. Uninstall the app.

  3. Get the new hash using the release or new debug keystore. Use this command:

    keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64
    
  4. Add the new hash on Facebook dashboard.

2
  • does anyone know if I should remove my old debug hash keys once I generated my release hash key on facebook?
    – jerbotron
    Aug 23, 2016 at 2:11
  • 2
    After updating new hash key also having same problem Aug 23, 2016 at 4:59
3

For me, this exact error was due to invalid permission strings. Happened on iOS and Android.

2
3

I faced the same problem.

It was a mistake on my side.

keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64

When typed this command, it prompted Enter keystore password:. I was giving the keyPassword instead storePassword and it didn't gave any error message instead generated a different hash!

1
  • this must be joke, same issue was here and i resolved by your solution, thanks !
    – ACAkgul
    Jul 20, 2020 at 18:38
2

I refer this,

https://developers.facebook.com/docs/android/getting-started

or just add below code in onCreate() method, which will return key hash.

 // Add code to print out the key hash
try {
    PackageInfo info = getPackageManager().getPackageInfo(
            "com.facebook.samples.hellofacebook", 
            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));
        }
} catch (NameNotFoundException e) {

} catch (NoSuchAlgorithmException e) {

}

Add above code to retrieve key,that key you can store

https://developers.facebook.com/docs/facebook-login/android

here. Now It will work.

It worked for me, hope will work for you too.

OR

This command may not give you latest keyhash.

keytool -exportcert -alias YOUR_RELEASE_KEY_ALIAS -keystore YOUR_RELEASE_KEY_PATH | openssl sha1 -binary | openssl base64

To get latest or active keyhash from android studio search 'hash' in your android studio's Logcat or android monitor while app is running and throwing above error. You will get different keyhash which is active. After pasting this searched keyhash in your console setting you may log be able to your app.

1

I was facing the same issue. I had my keyhashes defined perfectly, was still facing the same issue. I was not able to login even for the first time.

Solution to my problem was:

  1. Go to your app's dashboard here

  2. On the left pane, under products tab, ensure that you have Facebook Login added. If not, add it there.

If all your other configurations are in place. It works perfect after that.

1

This problem occurs because you've already authenticated the app via Facebook and your code may contain Authenticate every time Facebook (Find and Remove that).

Follow these steps:

  1. Go to Facebook settings.

  2. Remove your app.

  3. Make sure you've added Facebook Login in Facebook developer page and you've enabled Client OAuth Login.

  4. Go to your code and override the callback method:

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        mFacebookCallbackManager.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            Intent secondActivityIntent = new Intent(this, RedirectActivity.class);
            startActivity(secondActivityIntent);
        }
    }
    
  5. In the Oncreate method, call the AccessToken:

    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();
    
    if (accessToken != null && !accessToken.isExpired())
    {
        GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
            @Override
            public void onCompleted(JSONObject object, GraphResponse response) {
                if(null != object) {
                    try
                    {
                        Intent i = new Intent(MainActivity.this, Feedback.class);
                        startActivity(i);
                        String email = object.getString("email");
                        String birthday = object.getString("birthday");
    
                    }
                    catch (Exception ex)
                    {
                        Toast.makeText(MainActivity.this, ex.toString(), Toast.LENGTH_SHORT).show();
                    }
                } else {
                    // call your authentication process
    
                }
            }
        });
        Bundle parameters = new Bundle();
        parameters.putString("fields", "id,name,birthday,link");
        request.setParameters(parameters);
        request.executeAsync();
    }
    
2
  • I already overridden access tracker. But not resolving my issue Aug 22, 2016 at 5:33
  • First time I authenticated successfully. When I Uninstall and install now try to access Fb Login now AccessToken.getCurrentAccessToken() is null. Its not null in nexus devices right now issue is facing on Redmi devices and some of the samsung devices also. Aug 25, 2016 at 11:26
1

I was getting this error when signing in from a different account. when i signed in using developer account i recieved this error Facebook Login: "The application has disabled the Oauth client flow for Facebook integration" which was solved by enabling Client Oauth login from facebook developer account->myApp->products-> Facebook Login

1
  • This was actually the solution for us! Thanks a lot!
    – Wu Wei
    Oct 13, 2022 at 11:38
0

I had the same problem on my Redmi Note 3. Tested on Samsung. No problems. Wonder if it is Redmi specific.

4
  • Yes It will occurs in Redmi Note 3. I checked in Nexus Its works fine Aug 23, 2016 at 12:37
  • Mee to i am testing on Redmi Note3 :)
    – Anjum....
    Aug 23, 2016 at 19:42
  • I think it has to do with Redmi ROM or some settings. The Miui forum is down. Tried to allow window pop up in security settings for facebook. Didnt work.
    – Ben Looi
    Aug 23, 2016 at 23:34
  • I am trying to get console and server log from xiaomi note. The English forum en.miui.com is down. Not a fb connect bug but a redmi bug. :(
    – Ben Looi
    Aug 24, 2016 at 1:15
0

The problem for me is really with the hash key, It's not valid.

I had exactly the same problem and it was very hard to diagnose. The reason is that Facebook doesn't check the hash key at first login and it seems that the key is correct, but indeed it's not. Second, the error message is simply an idiocracy. Third is the resolution: try the following link, it helped me.

Better instructions to generate a valid hash key

0
0

I faced the same issue and I found that the hash key which I have generated to put in facebook developer console is not proper. I tried to generate hash key from different PC and it asked me to enter password for that particular keystore which was not the case in my PC. So make sure that you will asked to enter key store password while creating hash key then insert that hash key into facebook developer console.

Command to generate hash key:

keytool -exportcert -alias TYPE ALIAS HERE -keystore KEY_STORE_FILE_PATH_HERE | openssl sha1 -binary | openssl base64
0

I had the same problem today on my sites and then realised that I was using the old default_graph_version = v3.2. I've changed it to the latest:

default_graph_version = v4.0

Now everything works again. Give it a try.

0

The issue for me (at the time of writing this) was when adding hash directly in Facebook Login -> Settings page. For some strange reason it does not save it correctly.

I fixed this with going to Quickstart and adding hashes in one of the steps and hitting Save. (fix will probably be obsolete when they fix their web page)

I did not have an issue with the tool, it generated correct hash. People with wrong Play store hashes probably have Play store signing enabled or entered wrong credentials.

0

if you setup the key hash correctly, it may be related to the facebook app. This is occurring only on Android if the facebook application is installed on device! (to make sure, just uninstall the fb app and try again.) one solution is to authenticating using web and ignore the native fb app.

0

In our case, we use expo app and it does not support redirection to the app after login success. We needed to setup the configuration to not open the facebook app but the embedded browser or the phone's browser by specifying the behavior.

Facebook.logInWithReadPermissionsAsync({
  permissions: [
    "public_profile",
    "email",
    "user_birthday",
    "user_hometown",
    "user_location",
  ],
  behavior: "web"
})

Hope it help someone, we've lost many time solving this :)

Not the answer you're looking for? Browse other questions tagged or ask your own question.