17

My app uses a simple facebook login. I have entered the keyhash in my app dashboard, key_hash section and I was able to login successfully. Now I have published the app and tried to login, but it is showing a error message on a webview saying that

"Invalid android_key parameter. The key rX6qeRitkFCWui3de74rxB_qc1s does not match any allowed key. Configure your app key hashes at http://developers.facebook.com/apps/<my_fb_app_id>". 

Actually rX6qeRitkFCWui3de74rxB_qc1s is not my key hash which i have in native app. Where is it coming from? Anyways I entered this keyhash also in native app but getting the same error message and couldn't login still. Where am'i going wrong? Please help me.

Santhosh
  • 4,696
  • 11
  • 53
  • 86
  • you need to create it. Follow as @Indian suggested you in answer. It'll work. I'm sure. Once same prob I have faced. – TheLittleNaruto Aug 06 '13 at 06:52
  • 1
    Did you try putting the key hash from the error message into your app settings? The error message was designed to enable you to just copy/paste a key hash into your settings. – Ming Li Oct 21 '13 at 14:07
  • I solved this problem here! Here understanded cool![http://stackoverflow.com/questions/5306009/facebook-android-generate-key-hash/12405323#12405323][1] – Madi Jul 22 '14 at 05:07
  • @SANTHOSH did you got the answer – Ashutosh Salodkar Jan 27 '16 at 12:29
  • @AshutoshSalodkar : Try generating new keyhash using your app's keystore file used for signing the published app. This problem may be caused by providing the keyhash generated by your debug keystore which will only work with unsigned apk files. – Santhosh Jan 28 '16 at 04:17
  • I'm getting an error for this key hash 63y9********+******DK2jU= so I have added it in key hash of my app but still getting the same error – Ashutosh Salodkar Jan 28 '16 at 06:05

9 Answers9

26

You can generate a hash key through coding, you simply do one thing. Paste this code in main class (first class) then run the app and check the logcat where you will find the hash key.

One more thing, replace this package name "com.example.creeper" with your package name:

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

}
John Powell
  • 11,245
  • 6
  • 53
  • 64
Ram
  • 1,908
  • 3
  • 20
  • 30
  • 5
    this will generate a default debugging keyhash, but not for production. for production you need to generate keyhash using your own private certificate. as described here http://stackoverflow.com/questions/20506658/android-facebook-sdk-key-hash-does-not-match-any-stored-key-hashes-when-uploadi – manish Apr 12 '14 at 22:59
  • how can u say its working for me, manish read the question carefully then comment ...... – Ram Apr 17 '14 at 02:22
  • YOU MUST GET HASH FROM main class (first class) – formuser66 Dec 17 '14 at 21:16
  • @RishiGautam : My First class is SplashScreen Class and I am using the FB button in LoginActivity class so where do i exactly paste this code in SplashScreen or Login Activity class. Plus in the Facebook developers console i have added LoginActivity as my class name. So which one is my first class exactly. thanx – Sagar Devanga Jul 03 '15 at 11:52
  • The most critical part of this question is where the key hash "rX6qeRitkFCWui3de74rxB_qc1s" is coming from. I have a similar problem where Facebook is complaining that a hash does not match any stored key hashes. The key hash being displayed appears NOWHERE in my codebase. Understanding where this magic key hash comes from is key to understanding the process. This answer fails to illuminate the process. – Rjak Apr 22 '16 at 21:00
12

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 this two steps for make your app live

Step 1 Go to your application -> setting and add Contact Email then apply save Changes

Setp 2 Then goto Status&Review option and make sure this toggle is Yes i added a screen shot

enter image description here

Arpit Patel
  • 8,321
  • 4
  • 56
  • 70
5

Try generating new keyhash using your app's keystore file used for signing the published app. This problem may be caused by providing the keyhash generated by your debug keystore which will only work with unsigned apk files. please refer the step 5 of following link to understand how to generate a keyhash https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/

and update the same with app settings page of facebook.

Also check whether your package name and class name are correct.

Mahesh
  • 884
  • 6
  • 11
  • The first activity in my app is HomeActivity, and I have FBLogin button in a fragment called NewsListFragment and its container activity is SettingsActivity. Now what should I enter as class name in FB app settings? – Santhosh May 27 '13 at 12:15
  • 1
    have you tried adding the keyhash generated with your keystore used for signing the app? I think that will make it work. Anyway add the activity in which you are initiating the fb login. – Mahesh May 27 '13 at 12:34
  • try this for generating keyhash: keytool -exportcert -alias -keystore | openssl sha1 -binary | open ssl base64 – Mahesh May 27 '13 at 12:50
  • Generated keyhash with the keystore used for signing the app. And added in fb app settings. But not able to login still. – Santhosh May 27 '13 at 13:29
  • Are you getting the same error? Did you gave the same alias that as given in keystore file? – Mahesh May 27 '13 at 13:33
  • Did you gave the same alias as that given in your keystore file? – Mahesh May 27 '13 at 13:39
  • Yes. I have given the same. – Santhosh May 27 '13 at 13:42
  • [try this link](http://facebook.stackoverflow.com/questions/13281913/app-is-misconfigured-for-facebook-login-with-release-key-hash) Please try this link. May be it will help – Mahesh May 27 '13 at 13:48
3

Using Debug key store including android's debug.keystore present in .android folder was generating a strange problem; the log-in using facebook login button on android app would happen perfectly as desired for the first time. But when ever I Logged out and tried logging in, it would throw up an error saying: This app has no android key hashes configured. Please go to http:// ....

Creating a Keystore using keytool command(keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -sigalg SHA1withRSA -keysize 2048 -validity 10000) and putting this keystore in my projects topmost parent folder and making a following entry in projects build.gradle file solved the issue:

 signingConfigs {
        release {
            storeFile file("my-release-key.keystore")
            storePassword "passpass"
            keyAlias "alias_name"
            keyPassword "passpass"
        }    }

Please note that you always use the following method inside onCreate() of your android activity to get the key hash value(to register in developer.facebook.com site of your app) instead of using command line(keytool -exportcert -alias -keystore | openssl sha1 -binary | openssl base64) to generate hash value as command line in some cased may out put a wrong key hash:

    public  void showHashKey(Context context) {
        try {
            PackageInfo info = context.getPackageManager().getPackageInfo("com.superreceptionist",
                    PackageManager.GET_SIGNATURES);
            for (android.content.pm.Signature signature : info.signatures) {
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());

                 String sign=Base64.encodeToString(md.digest(), Base64.DEFAULT);
                Log.e("KeyHash:", sign);
                //  Toast.makeText(getApplicationContext(),sign,     Toast.LENGTH_LONG).show();
            }
            Log.d("KeyHash:", "****------------***");
        } catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
e.printStackTrace();
        }
    }
Sandeep.R
  • 61
  • 1
2

You need to to a keyhash from your debug.keystore or if you signed it with release key, than with that. Make sure, that your alias-name is also correct. That has an effect at your keyhash.

Check this out: How to create a Facebook key hash?

Community
  • 1
  • 1
Luser_k
  • 21
  • 1
2

For example, the key provided in the error is "rX6qeRitkFCWui3de74rxB_qc1s", then the list of hash code in Facebook, you try and put this code at the end of the end "=" getting rX6qeRitkFCWui3de74rxB_qc1s= and see if it worked.

Isaac G Sivaa
  • 1,221
  • 4
  • 14
  • 32
1

Try to generate new key hash and edit it in facebook developers and register app with new key hash again.

anddevmanu
  • 1,409
  • 14
  • 19
1

Here is the C# version for the benefit of anyone trying to get the Xamarin sample to work.

    public  void showHashKey(Context context) 
    {
        try {
            PackageInfo info = context.PackageManager.GetPackageInfo("com.facebook.samples.hellofacebook", PackageInfoFlags.Signatures);
            foreach (Android.Content.PM.Signature signature in info.Signatures) {
                MessageDigest md = MessageDigest.GetInstance("SHA");
                md.Update(signature.ToByteArray());

                var sign = Base64.EncodeToString(md.Digest(), Base64Flags.Default);
                Log.Info("KeyHash:", sign);
            }
            Log..Info("KeyHash:", "****------------***");
        } catch (PackageManager.NameNotFoundException e) {
            e.PrintStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.PrintStackTrace();
        }
    }
BenBtg
  • 816
  • 1
  • 8
  • 20
0

For me, when I ran the keytool command and it prompted me for a password, I interpreted this to mean I need to choose a password for the hash. In fact, you need to provide they password to the keystore (the location where the hash is kept). Funny thing is (not funny, "ha ha"), it will accept any password and output a hash for you. That caused my hash to not match. Luckily I had stored my password in OS X keychain long ago, so I found what it really is. I tried the correct password and got a different hash which worked. Note that the default keystore password is android, so try that, it might be what you're missing.

I really think an incorrect password ought to reject you rather than outputting a hash, I wonder if this is a bug – if so, please leave a bug report link in the comments.

ABCD.ca
  • 2,105
  • 3
  • 28
  • 24