2

I am trying to use facebook api for login on my android application. After following the tutorials I was able to get the confirmation screen after clicking login by facebook button. But when i run my application second time I get "Facebook key hash does not match any stored key hashes" error.

I follow other posts on stackoverflow, deleted my application and created once again etc. but on second run I again get the same error.

Facebook key hash does not match any stored key hashes

Do you know what can be wrong and why I do not get on first run but I get this error on second run?

Community
  • 1
  • 1
cincin
  • 67
  • 1
  • 7

2 Answers2

5

try this:

 public void Get_hash_key() {
        PackageInfo info;
        try {
            info = getPackageManager().getPackageInfo("your_package_name", PackageManager.GET_SIGNATURES);
            for (Signature signature : info.signatures) {
                MessageDigest md;
                md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                String something = new String(Base64.encode(md.digest(), 0));
                //String something = new String(Base64.encodeBytes(md.digest()));
                Log.e("hash key", something);
            }
        } catch (PackageManager.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());
        }
    }

add your package name and call this function in onCreate() of your Mainactivity

it will print the Hash key on logcat...

copy and paste the key on developer panel ,remove other keys

rafsanahmad007
  • 23,683
  • 6
  • 47
  • 62
  • I tried this but on second run again it fails, because on second run it creates different hash code. I think that is the problem. As I understand after every run the code changes but on the server there is only code which I registered and therefore it does not match. So why my hash code changes always? – cincin Jan 15 '17 at 09:34
0

Create a valid keystore to your android app:

(Windows)

keytool -genkey -v -keystore fisherbook.keystore -alias fisherbook -keyalg RSA -keysize 2048 -validity 10000

Generate facebook hash key:

(Windows)

keytool -exportcert -alias <KEYSTORE_ALIAS> -keystore <COMPLETE_KEYSTORE_PATH> | openssl sha1 -binary | openssl base64 

Or look at facebook error: "Invalid key hash. The key does not match any store hashes..." There is your facebook hash key!

Then put your hash at app/settings (android) at facebook developer website.