MuhammadNe
MuhammadNe

Reputation: 704

Facebook android app error : Invalid key hash

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"

Upvotes: 2

Views: 29693

Answers (6)

Bhavik Nathani
Bhavik Nathani

Reputation: 499

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.

Upvotes: 4

NehaK
NehaK

Reputation: 2727

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.

Upvotes: 9

Berat Ey&#252;boğlu
Berat Ey&#252;boğlu

Reputation: 1733

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.

Upvotes: 6

Jorge Gamez
Jorge Gamez

Reputation: 1

there are two possible solutions that might help, each one of these got it done for me in different occassions so here we go.

(assumming that you typed the hash key that the app told you to and didn't work you)

  1. You should delete de debug.keystore file located usually in "C:\Users\yourUserName.android", then recompile the project, and get the new hash key with thes new debug.keyhash (as stated here ). Then these new keyhash should work.

2.These is a little more tricky. Maybe the reason why your facebook developer dashboard key hash doesn't work even if you typed it, is because your facebook app ID has changed by the moment you built the apk (this happened to me because i had previous versions of my app and it was giving me the past id, even though i had it specified in config.xml). So, in my case i have a cordova project so i went to "C:your_CordovaProject\platforms\android\res\values\facebookconnect.xml" and open the file, here you gotta check if the fb_app_id is the same that you have in your facebook dashboard. if it's not (it wasn't in my case) what you have to do is --Remove your facebook plugin, --add it again and --specify your app id and name one more time like this:

cordova plugin add cordova-plugin-facebook4 --save --variable APP_ID="123456789" --variable APP_NAME="myApplication"

then i did the hash key process again and it worked. Hope it helps

Upvotes: 0

Neal Ahluvalia
Neal Ahluvalia

Reputation: 1548

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.

Upvotes: 5

Max Zavernutiy
Max Zavernutiy

Reputation: 1869

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

Upvotes: 6

Related Questions