0

I'm developing an Android application that uses Facebook Authentication. In debug mode, i use the debug key 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 in Google play store, so i need to generate a release key hash. I used the method mentioned in facebook developers doc which is:

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

For the RELEASE_KEY_PATH it's the path of kaystore generated when exporting project to apk.

I added the hey hash generated to facebook app but i still have the error:

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

When i add the hey hash generated by java code it works, but i can't do it for each device, i need to publish my app so that every one can use it.

What is the solution? Please help me.

Najoua Mahi
  • 304
  • 3
  • 16

1 Answers1

1

I have solved my problem :D

So to have the release key 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!!

Najoua Mahi
  • 304
  • 3
  • 16
  • Same thing on the device instead in emulator? – David Dimalanta Jan 23 '15 at 03:50
  • 1
    If you want to test your application with your own Facebook developer account you don't need to use the apk, you can just run your application in an emulator or on the devise and get the key hash generated. But if you want to publish your application you need to use the solution i mentioned below. Good luck. – Najoua Mahi Jan 23 '15 at 09:27