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.