Invalid key hash. key hash doesn't match any stored key hashes facebook android

I am developing an Android application using Facebook Authentication. In debug mode, I use the debug hash generated by the code:

try {
            PackageInfo info = getPackageManager().getPackageInfo(
                    "com.org.package", PackageManager.GET_SIGNATURES);
            for (Signature signature : info.signatures) {
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                String sign = Base64
                        .encodeToString(md.digest(), Base64.DEFAULT);

                    Log.e("MY KEY HASH:", sign);

            }
        } catch (NameNotFoundException e) {
        } catch (NoSuchAlgorithmException e) {
        }

      

Now I want to publish my app to the Google Play store, so I need to generate a release hash. I used the method mentioned in facebook developers doc which:

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

      

For RELEASE_KEY_PATH, this is the kaystore path generated when exporting the project to apk.

I added a heh hash generated for the facebook app, but I still have the error:

invalid key hash. key hash does not match any stored key hashes facebook android.

When I add the heh hash generated by the java code, it works, but I can't do it for every device, I need to publish my app so everyone can use it.

What solution? Please help me.

0


source to share


1 answer


I solved my problem: D

So, in order to have a release hash you need to install the apk file in your Android emulator and add the key generated by the following code to your Facebook app:



try {
            PackageInfo info = getPackageManager().getPackageInfo(
                    "com.org.package", PackageManager.GET_SIGNATURES);
            for (Signature signature : info.signatures) {
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                String sign = Base64
                        .encodeToString(md.digest(), Base64.DEFAULT);

                    Log.e("MY KEY HASH:", sign);

            }
        } catch (NameNotFoundException e) {
        } catch (NoSuchAlgorithmException e) {
        }

      

Good luck!

+1


source







All Articles