简体   繁体   中英

Android Key Hash for Facebook with Cordova

I'm developing a hybrid app with Meteor and Cordova. I'm trying to configure Facebook Connect and got it working on iOS but I'm stuck on android. I cannot seem to find the correct key hash. I always get the message:

Invalid key hash. The key hash ... does not match any stored key hashes.

I already tried to find the correct key hash via the following command:

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64

and the standard password "android". I added the resulting key to Facebook but it didn't help. I also tried the tool in the following post . It gave me another key which also did not work. Any ideas?

Meteor uses its own debug keystore when creating an android app via meteor run android-device . The keystore can be found at ~/.meteor/android_bundle/.android/debug.keystore .

Use the following code and the keystore password android for creating your keyhash:

keytool -exportcert -alias androiddebugkey -keystore \
~/.meteor/android_bundle/.android/debug.keystore | openssl sha1 -binary | openssl base64

I went through the same problem and simply had to put the key which was on the error message on FB settings. It worked.

Facebook keyhash works with your application's package name and keystore.

Get your apk signed with a production keystore and use below code to get the facbook keyhash

try {
PackageInfo info = getPackageManager().getPackageInfo("your package", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
    MessageDigest md = MessageDigest.getInstance("SHA");
    md.update(signature.toByteArray());
    Log.e("MY KEY HASH:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {

} catch (NoSuchAlgorithmException e) {

}

The facebook Keyhash wil start with '=' equals to sign. For testing purpose you can have both keyhash from debug keystore as well as production keystore.

More information is available here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM