ionic with phonegap-facebook-plugin: invalid hash key

351 Views Asked by At

It worked ok. I logged in with facebook. After a while, i don´t know exactly the reason, when I try to login with facebook, it starts to show:

Invalid key hash. The key hash ..... does not match any stored key hashes. Configure your app key hashes at http://developers.facebook.com/apps/...

The hash key that is showing in the error message it´s not the hash key set in the developers facebook and had worked before. I tried to put this hash in the developers.facebook but does not work too.

After hours of research:

  • deleted the app in Facebook developers
  • remove cordova plugin from ionic project
  • Delete the file debug.keystore under C:\Users\yourUserName.android
  • Generate a new key with "keytools"
  • Create a new app on developers.facebook.com and add the new hash key

Then it started to work again. But now, its showing me the same "invalid hash key" again :(

Any help?

Edited:

I deleted just the debug.keystore and ran "ionic run android". Then showed me the same error but with a new hash key, I tryeid again to put the hash key that they show in the error message and it is working now. But it´s very strange, because the hash key that I generated with "keytools" and put in developer.facebook for the first time, was just for nothing.

I follow this tutorial: https://ionicthemes.com/tutorials/about/native-facebook-login-with-ionic-framework

2

There are 2 best solutions below

0
On
  • Download APK (your_apk_name.apk)
  • Run Command keytool -list -printcert -jarfile your_apk_name.apk
  • Copy the SHA1 value
  • Go to http://tomeko.net/online_tools/hex_to_base64.php
  • paste SHA1 value & hit convert.
  • Copy the output(base64) and use this as your facebook hash.
0
On

You need to add all key hashes that you see in those error messages to the setting of your Facebook app. Go to developers.facebook.com/yourappid, to settings > basic, scroll down to key hashes and add it there. We've got 4 different hashes for ours now and I'm sure they'll be more going forward.

It seems that having other applications on the users phone that are using Facebook login can change the hash needed by your app in login. So like, if you've got the main Facebook app on your phone, it'll require a different hash for your app's login than if you have just Facebook Messenger. This is our working theory that holds up against all evidence so far.

I'd recommend setting up a logger for client errors so you can get those hashes as they pop up. This obviously isn't the ideal solution so I'd love to hear what others find out about this but, for now at least, it's working.