How To Create A Facebook Key Hash?
In the Facebook android tutorial we are told to use following code to create a key hash: keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl s
Solution 1:
try
try {
PackageInfoinfo= getPackageManager().getPackageInfo("com.eatapp", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigestmd= MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.e("MY KEY HASH:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
in your main Activity :-) This is the only solution it works for me for Android SDK 3.0
Solution 2:
You can create this way
keytool -exportcert -alias androiddebugkey -keystore c:\Users\<your windows defaultuser>\.android\debug.keystore | openssl sha1 -binary| openssl base64
Enter keystore password: android
Solution 3:
/**
* Generates the hash key used for Facebook console to register app. It can also be used for other sdks) Method copied from: https://developers.facebook.com/docs/android/getting-started/
*/publicstatic String printHashKey(Context ctx) {
// Add code to print out the key hashtry {
PackageInfoinfo= ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigestmd= MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
return Base64.encodeToString(md.digest(), Base64.DEFAULT);
}
} catch (NameNotFoundException e) {
return"SHA-1 generation: the key count not be generated: NameNotFoundException thrown";
} catch (NoSuchAlgorithmException e) {
return"SHA-1 generation: the key count not be generated: NoSuchAlgorithmException thrown";
}
return"SHA-1 generation: epic failed";
}
Solution 4:
In eclipse, window -> preferences -> Android -> build -> default debug keystore, copy the path to replace the ~/.android/debug.keystore
Solution 5:
When having the error in the log, when trying to login to Facebook, look for something that looks like:
Invalid key hash. The key hash *** does not match any stored key hashes. Configure your app key hashes at http://developers.facebook.com/apps/565561836797777
where "***" is the key that you need to use.
Post a Comment for "How To Create A Facebook Key Hash?"