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 sha1 -binary | openssl base64
Is this the exact code to use in all situations? For example instead of ~/.android/debug.keystore
should it something like C:/folderone/foldertwo/.android/debug.keystore
?
As you can see I'm unsure of whether inverted commas are required or not, whether full paths are required or not!
Is anyone able to provide a real world example?
See
https://developers.facebook.com/docs/mobile/android/build/#sso
Go to the Facebook Developer site. Log into Facebook and, using the dropdown menu in the top-right, go to Developer Settings: In your developer settings, select Sample App from the menu, and add and save your key hash into your profile: You can add multiple key hashes if you develop with multiple machines.
If you don't have any idea how to get the SHA1 Fingerprint then you can go through the example How you can get the SHA1 Fingerprint for Android. After getting the SHA1 you have to open a link tomeko.net where you will see the option to insert SHA1 and it will convert your SHA1 into Key Hash.
try
try {
PackageInfo info = getPackageManager().getPackageInfo("com.eatapp", 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) {
}
in your main Activity :-) This is the only solution it works for me for Android SDK 3.0
You can create this way
keytool -exportcert -alias androiddebugkey -keystore c:\Users\<your windows default user>\.android\debug.keystore | openssl sha1 -binary | openssl base64
Enter keystore password: android
/**
* 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/
*/
public static String printHashKey(Context ctx) {
// Add code to print out the key hash
try {
PackageInfo info = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = 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";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With