In the Facebook android tutorial we are told to use following code to create a key hash:
keytool -exportcert -alias androiddebugkey -keystore ~/.andro
One brute force option is to just go ahead and try to share something from your app. My app then displays a Facebook page with the key it is trying to match. Then you can just copy this key and put it in your Facebook 'Settings' page on your developer Facebook account.
Not ideal, but in a pinch it may be helpful.
There are two ways to generate Hashkey for Facebook.
You can use the following code snippet
try {
PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest messageDigest= MessageDigest.getInstance("SHA");
messageDigest.update(signature.toByteArray());
String hashKey = new String(Base64.encode(messageDigest.digest(), 0));
Log.i("Hash Key ", "value is " + hashKey);
}
} catch (NoSuchAlgorithmException e) {
Log.e("Exception ", "is ", e);
} catch (Exception e) {
Log.e("Exception ", "is ", e);
}
You can create Hashkey for Facebook Online by pasting your SHA1 on This link
Happy Coding :)
/**
* 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";
}