1

I'm writing an android application with my friend. In the application we use Facebook SDK and a login button. We already setup the hash key using the code similar to what facebook suggests Code in the app profile in facebook. We also wrote the key under Settings -> Key Hashes. When testing the login on real device , if the native facebook app is using my friends account our application can login , but if i use my account I get the error :

Invalid key hash . The key hash XXXXXXXXX.... doesn't not match any stored key hashes . configure your app key hashes at ......

We checked in the application profile and my account is also written there with Admin privileges.

Menelaos Kotsollaris
  • 4,517
  • 6
  • 50
  • 61
Epsilon
  • 73
  • 2
  • 12

2 Answers2

1

Run this code in your application and you will have the Hash Key:

try
{
    //paste Your package name at the first parameter
    PackageInfo info = getPackageManager().getPackageInfo("PUT_YOUR_PACKAGE_NAME_HERE",
            PackageManager.GET_SIGNATURES);
    for (android.content.pm.Signature signature : info.signatures)
    {
        MessageDigest md = MessageDigest.getInstance("SHA");
        md.update(signature.toByteArray());
        String sign = Base64.encodeToString(md.digest(), Base64.DEFAULT);
        Log.e("MY KEY HASH:", sign);
        Toast.makeText(getApplicationContext(), sign, Toast.LENGTH_LONG).show();
    }
}
catch (PackageManager.NameNotFoundException e)
{
}
catch (NoSuchAlgorithmException e)
{
}

For a full facebook login example see this answer.

Since you are logging from other devices, you should enable your app in the facebook console. Check this answer to see how.

Community
  • 1
  • 1
Menelaos Kotsollaris
  • 4,517
  • 6
  • 50
  • 61
0

Make sure you're using the correct password as keytool apparently doesn't reject an incorrect one and will generate an incorrect hash. The default keystore password is android

ABCD.ca
  • 2,105
  • 3
  • 28
  • 24