Facebook SDK (Android) - Invalid Key Hash

I’ve been working on a Unity game with Facebook integration. The testers and I were able to sign into our game with Facebook just fine a few days ago, but now neither of the 2 testers can log in anymore. I can log in just fine however (I’m an admin), and my test Facebook account is also able to sign in with no problems (it’s a tester). None of the settings have been touched in either the Facebook dashboard, or the Facebook Settings asset in the Unity project.

When the testers click on the “Log Into Facebook” button in our game, the Facebook window comes up, but it doesn’t allow them to sign in. Instead, they suddenly get this “Invalid Key Hash” error. I’ve run into this in the past, but I haven’t been able to resolve the issue.

I created a Facebook app, generated the debug and release key hashes using the commands provided by the FBSDK Docs, added the generated key hashes provided by the command line to my Facebook app in its dashboard, made sure the Facebook Settings asset in Unity was up-to-date (provided the Facebook App ID, package name, etc, and regenerated the AndroidManifest), and the people testing our game are added to the “Tester” role in the Facebook app’s dashboard. I’ve also tried regenerating the debug and release keys, but no luck…

I’ve tried to display the key hash in the Unity game using the Facebook Unity SDK, but the string always comes up as empty. It even shows up empty on my device where Facebook sign in works. I also wait until the Facebook SDK is initialized before updating my display text with the key hash. I’m trying to get the key hash from the Facebook C# SDK’s FB.Android.KeyHash property, but it’s always an empty string…

Any ideas on what is going on? I’m unable to reproduce the issue on my own device because it always works for me.

UPDATE:
After some more research, I found that having the Facebook app installed on Android devices affects the Invalid Key Hash error for derived builds. I didn’t have the Facebook app installed on my Kindle while the testers each had the Facebook app installed on their devices. I installed the Facebook app on my device, and the sign-in worked for local builds, and when I side-loaded the “Original APK” uploaded to Google Play. However, side-loading the “Derived APK” from Google Play didn’t work for me.

This is good because now I’m getting the error on my device. The problem is, I haven’t been able to solve the problem yet. The only thing I can think of is that the keystore’s file name has a hyphen in its name, and so does the alias we’re using… When using the command line to generate key hashes, I noticed that I get different results when putting my keystore path in quotes vs no quotes. There aren’t any spaces in the path, but there are hyphens. Could that be the issue?

UPDATE 2:
I finally figured it out. Turns out, we were signing the APK that gets posted in the Google Play store using the signing key that Google Play generates instead of the release signing key generated from the keystore. I had to go into the App Signing settings in Google Play, get the SHA1 value (it’s in hexadecimal notation), and convert it to base64. That result is what needed to go into the Facebook dashboard.

1 Like

UPDATE:
After some more research, I found that having the Facebook app installed on Android devices affects the Invalid Key Hash error for derived builds. I didn’t have the Facebook app installed on my Kindle while the testers each had the Facebook app installed on their devices. I installed the Facebook app on my device, and the sign-in worked for local builds, and when I side-loaded the “Original APK” uploaded to Google Play. However, side-loading the “Derived APK” from Google Play didn’t work for me.

This is good because now I’m getting the error on my device. The problem is, I haven’t been able to solve the problem yet. The only thing I can think of is that the keystore’s file name has a hyphen in its name, and so does the alias we’re using… When using the command line to generate key hashes, I noticed that I get different results when putting my keystore path in quotes vs no quotes. There aren’t any spaces in the path, but there are hyphens. Could that be the issue?

Funny thing this happened to me just now on a game i have published for 2 months and has Facebook SDK integrated for more than a month , everything was working great till i tested it again today to prepare for the new demands of Facebook, if anyone knows what could trigger this…

Have similar problem: I integrated FB plugin and all works great while I do builds via Unity Editor directly to Android device with Unsigned (debug) and Development Build Settings. In our work flow we use Unity Cloud Builds to deliver builds, so I created Android Configuration with Auto Generated Debug Keystore Signing Credentials and Development Build Settings.

Now I have 4 different scenarios:

  1. Local Build without FB App on device - Works
  2. Local Build with FB App on device - Works
  3. Cloud Build without FB App on device - Works
  4. Cloud Build with FB App on device - Doesn’t work, Invalid key hash Error

Does anyone had similar issues?

As mentioned above. Facebook app overwrites key hash of build. Any solutions/workarounds?

my case, it works normal without facebook app.
and hash error after install facebook app.

solution that works for me is to convert the sha1 key to base64, using this link

http://tomeko.net/online_tools/hex_to_base64.php

My Key Hash like this.
UW3GpdGE3mosX+YrIkdQ8RzP4qw=
I need to convert it into base64 right ?

you need the SHA1 hexadecimal from keystore that look like this:
d3:f0:26:3c:a2:ac:71:fe:c0:09:57:54:b1:e2:11:d9:91:9d:72:cd

and then convert it to base64 with that url
the result will be like your key hash, but different result.
I know its weird, but it worked for me

1 Like

You should look at this answer, if you still need help: https://discussions.unity.com/t/535628

Basically, once creating the keystore in Unity, from Publishing Settings in Android Player Settings, you shall go to keytool.exe location.
Then open a prompt window and type: keytool -exportcert -alias aliasName -keystore D:\mygames\mygame\user.keystore -list -v
Then it asks you the pwd you entered to create the keyhash.
Finally it displays the certfiicate fingerprints and one of them is the SHA1 hex.