Facebook android app error : Invalid key hash

28,137

Solution 1

As I understand you've got your key hash, but still I'll put here the code for getting it in the console.

PackageInfo info;
try {
    info = getPackageManager().getPackageInfo("com.your.project.package", PackageManager.GET_SIGNATURES);
    for (Signature signature : info.signatures) {
        MessageDigest md;
        md = MessageDigest.getInstance("SHA");
        md.update(signature.toByteArray());
        String something = new String(Base64.encode(md.digest(), 0));
        //String something = new String(Base64.encodeBytes(md.digest()));
        Log.e("hash key", something);
    }
} catch (PackageManager.NameNotFoundException e1) {
    Log.e("name not found", e1.toString());
} catch (NoSuchAlgorithmException e) {
    Log.e("no such an algorithm", e.toString());
} catch (Exception e) {
    Log.e("exception", e.toString());
}

Where "com.your.project.package" is the package of your project =)

Next thing, dont delete previous key hash, they don't conflict I think. For example I have 2 keyhashes in my facebook app.

And the latest thing, and I think this is the problem. Go to the Status&Review of your app at the developers.facebook. And switch your application to public. public access to app

Solution 2

Keyhashes differs with .apk files generated from different systems. So best solution is - when you get error

"Invalid key hash. The key hash "<KEYHASH>" does not match any..."

then write or Copy that "<KEYHASH>" and Put that in facebook developer page by go to apps-> settings-> android. If doesn't work then put "=" after keyhash you copied from error and try again. And don't forget to live your project.

Solution 3

You should get new key;

Step 1. If you dont have OpenSSL lib, Download here

Step 2. And Extract it. create a folder- OpenSSL in C:/ and copy the extracted code here.

Step 3. And open cmd and go C:\Program Files\Java\jdk1.7.0_79\bin

Step 4. And execute this command -

keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | "C:\OpenSSL\bin\openssl" sha1 -binary |"C:\OpenSSL\bin\openssl" base64

Step 5. Get key and go developer facebook website

Step6. Add key to your project.

That's it.

Solution 4

Add the key Provided in your app on

http://developers.facebook.com/apps/

Additionally, in last add "=" symbol

ex. you are getting 2jmj7l5rSw0yVb/vlWAYkK/Y than in Facebook page, add 2jmj7l5rSw0yVb/vlWAYkK/Y= That Last "=" sign is important.

I spent an hour generating the keyhashes, than tried this trick.

Solution 5

This worked for me.

Copy the APK to your PC in Program Files\java\jdkX.X.X_XXX\bin folder

In my case it's C:\Program Files\Java\jdk1.8.0_191\bin

Open CMD in this directory and type the following

keytool -list -printcert -jarfile YOUR_APK_NAME.apk

Copy the SHA1 value to your clipboard It will be something like this: 79:D0:E6:80:4E:28:1E:D1:88:28:CB:D7:E6:BE:2E:0C:FB:24:98:52

Then go to http://tomeko.net/online_tools/hex_to_base64.php to convert your SHA1 value to base64.

This is what Facebook requires get the generated hash " ********************= " and copy the key hash to your Facebook developers app settings.

Share:
28,137
MuhammadNe
Author by

MuhammadNe

Updated on December 31, 2020

Comments

  • MuhammadNe
    MuhammadNe over 3 years

    I have imported the Facebook SDK to my android project, first time I logged in to Facebook from my android application it worked, but the second time I got this error :

    Invalid key hash. The key hash "..." does not match any stored key hashes. Configure your app key hashes at http://developers.facebook.com/apps/..

    I also tried to enter the key they provided in this error but it didn't work.

    EDIT: I have used the cmd command to which it generates a key and asks for the password which is "android"