Facebook hash key breaks the Facebook login button

174 views Asked by At

I initially had used OpenSSL to get my key hash, but after doing a lot of research, I read that, using a snippet of code, I can generate one which is the better method. These hashes differed and now when I use the hash key provided by this chunk of code:

try {
    PackageInfo info = getPackageManager().getPackageInfo("com.myapp.default",
                PackageManager.GET_SIGNATURES);
    for (Signature signature : info.signatures) {
        MessageDigest md = MessageDigest.getInstance("SHA");
        md.update(signature.toByteArray());
        Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
    }
} catch (PackageManager.NameNotFoundException e) {
} 
catch (NoSuchAlgorithmException e) {
}

It breaks my Facebook login button. What I mean by break is that when I click, nothing seems to happen. It displays a loading icon, but then nothing. When I switch back to the original hash, it gives me an error that says

Invalid key hash. The key hash xxx does not match any stored key hashes.

Then, it tells me to configure my key hashes on the Facebook developer site. Can anyone explain to me what I have done wrong or what I need to do to fix this? I had test apps on Facebook, but I deleted them and only have the real one.

Something to note is that when I use the original key hash (the one I got from OpenSSL) and it's the FIRST time logging in via my app, it will work (ask for permissions and whatnot). It just seems to fail everytime after that.

Hash link - https://i.stack.imgur.com/T4fBB.jpg

2

There are 2 answers

0
Kyle Pittman On BEST ANSWER

It means you have already authorized the app but when you click login it has no where else to go so it just sits on the same screen.

1
Fahim On

You need to make sure that the key hash is putted in the Facebook app account.

Key hash mismatch issue only occurs when you don't have added them in fb app account and using different one in the app.