When I was about to post a message in facebook, I received a following error message on facebook login page.
'Invalid key hash. The key hash ...... does not match any stored key hashes'
I'm using various Android devices.
When I use Galaxy s3, I didn't get the error .
But when I use Galaxy s4, I got the error.
And when I use Nexus 5, I didn't get the error
But when I use Xperia A, I got the error.
why does this symptom occur?
I tried following command to generate key hash.
keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64
But same error is shown. I also tried enter hash key to facebook developer site. The hash key was in the error message. but it didn't work.
And I found a solution of one.
When I remove connection between my application and Facebook, I could post a message.
But I think removing connection is unusual solution. moreover, even if I could post by using Galaxy s4, I can't post by using Xperia A. even if I could post by using Xperia A, I can't post by using Galaxy s4.
How should I fix this problem? if there is someone who knows answer, please tell me the solution.
You can use below code to generate keyhash to upload to facebook developers site:
/**
* generates key hash for facebbok
*/
private void GetKeyHash()
{
PackageInfo info;
try
{
info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures)
{
MessageDigest md;
md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
String keyhash = new String(Base64.encode(md.digest(), 0));
// String something = new String(Base64.encodeBytes(md.digest()));
Log.e("keyhash", "keyhash= " + keyhash);
System.out.println("keyhash= " + keyhash);
}
}
catch (NameNotFoundException e1)
{
Log.e("name not found", e1.toString());
}
catch (NoSuchAlgorithmException e)
{
Log.e("no such an algorithm", e.toString());
}
catch (Exception e)
{
Log.e("exception", e.toString());
}
}
Try to put this code inside first screen of your app.
Run your app and then check the logcat to get find debug key hash.
To get the signed key hash, created signed APK, install and open the app in device and then check the logcat of that device.
In both cases, logcat will show something like below:
04-10 12:07:33.710: E/keyhash(362): keyhash= ncoE5ojihY80FbI23/xEAdSfeS0=
04-10 12:07:33.710: I/System.out(362): keyhash= ncoE5ojihY80FbI23/xEAdSfeS0=
Once you get these keyhashes(debug and signed), upload them to facebook developers site and then do whatever you want to do.
Reference link
I hope this might help you or someone else.