Android Facebook integration with invalid key hash

The generated hash key is wrong. You may get the hash key using two steps.

One is through a command prompt. Another one is through coding. The hash key through a command prompt is working on the first time only. I don't know the reason. I have also got the same problem. So I tried it through programmatically.

Follow these steps:

Paste the following code in oncreate().

try {
    PackageInfo info = getPackageManager().getPackageInfo(
                           "com.example.packagename",
                           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) {
}

Modify "com.example.packagename" with your package name in the above coding without fail (you may find your package name in the Android manifest file).

Run your application. Go to the activity where you pasted the above code. In the LogCat file, search for "KeyHash". You may find a key hash. Copy the key hash and go to Facebook application dashboard page. Go to settings and enter the details like in the below image.

Enter image description here

Once you finished the above step, relaunch the app again. You may now log into Facebook. For more details about key hash, check the link.

If you add wrong information in the settings page, it means it will give some error. So use the correct information there. And also if the public (other than you) need to use your application means you need to enable the permission (change "yes" in the "Status & Review" next to the setting).


If you are using Google Play App signing:

Open the App signing section in Google Play Console, and get the SHA-1 hash under App signing certificate. Then convert it to Base64, for example with this tool: Hexadecimal -> base64 string decoder

Console screenshot

Convert to Base64 screenshot


If you are facing this problem then put this key into your developer.facebook.com:

Enter image description here

Then make sure your app is live on developer.facebook.com.

This green circle is indicating the app is live:

Enter image description here

If it is not then follow these two steps for make your app live:

Step 1 Go to your application→settingadd Contact Email and apply Save Changes.

Step 2 Go to the App Review option and make sure this toggle is Yes. I added a screenshot:

Enter image description here

Note: If you want to copy the hashkey, check the BlueServiceQueue in LogCat.


I got the same problem. I was sure that it was due to very small fault and yes it was!

I found the solution:

When generating the debug hash key in my computer, I entered the password of my system. But the password should be the following -

Enter keystore password: "android". This was the only problem in my case.

----- For generating Debug key hash, use this command -

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64

Enter keystore password: 'android'

----- To Generate Release key hash, use this command -

keytool -exportcert -alias "alias of keystore" -keystore "Your path to the keystore when signing app" | openssl sha1 -binary | openssl base64

Provide your keystore password after executing this command.