1

The error of using an invalid hash key error when using the Facebook SDK in Android apps seems to be rather common. And the solution I found in this Stackoverflow article worked perfectly. I created the hash key programmatically in my app and did a Copy&Paste of the key into the interface of the Facebook Developer page of my app.

Despite finding this and alternative solutions, I couldn't find a good explanation why I got this error all of a sudden.

  • When I use the keystore command below, I still get the same hash key that was already registered on my Facebook developer page and which worked neatly so far (so right now I'm having 2 registered hash keys)

    keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64
    
  • I didn't change the development environment, i.e., the PC to develop my app.

  • Just a couple of hours before I got this error, I gave the app to a new registered tester, who could logged into my app perfectly fine

  • I'm currently only developing and testing, so the app is not made public yet

  • Singing in and out still worked fine on the emulator. Only on my own phone I use for testing the app on a physical device I suddenly got this error after I signed out and wanted to sign in again.

I'm just trying to understand what's going on here so I know what to expect and what to do once I go public with the app. As I understand, there's a debug key and a production key. But even if the new key is the production key, why did this happen?

Why are the hash keys - the one I generate using the keytool command and the one that I generate within the app - different?

Community
  • 1
  • 1
Christian
  • 3,239
  • 5
  • 38
  • 79

1 Answers1

1

This appears to be a bug on Facebook's end.I've been dealing with the same issue for the past 24 hours. I tried everything from creating a new Facebook app and using the new Facebook Id and App Secret (worked for a minute and then I started getting the same error message again), to deleting app on device and even updating Facebook SDK.

Solution

I finally got past it by copying the keyhash I was getting in the error message and replacing it with the old one on the developer console.

You can copy it directly from the debug tab in Android monitor.

If you are not sure how to get this, just log it from the callback method:

        ...
        @Override
        public void onError(FacebookException error) {
            Log.d(TAG, error.getMessage());
            // ...
        }
Ojonugwa Jude Ochalifu
  • 26,627
  • 26
  • 120
  • 132
  • 1
    Ojonugwa, thanks! As I mentioned, solving the issue was reasonably straightforward. It's just that I could find any solid information on the Why. – Christian Feb 27 '17 at 10:00