I am making an android app where the user can log in with Facebook (through Firebase through FirebaseUI). I am new to android development and Facebook android authentication. The log in with email, gmail and twitter all work, but the log in with Facebook not, because i need this hash key...
When i set up Facebook authentication and click on log in with Facebook I am getting the following error.
Invalid key hash. The key hash `[keyhash1=]` does not match any stored key hashes. Configure your app key hashes at https://developers.facebook.com/apps/[app id].
Note that the [keyhash1=]
that they display is different than the key hash that i get when i run in command line this [keyhash2=]
:
keytool -exportcert -alias androiddebugkey -keystore [my name]\.android\debug.keystore | “C:\Users\[my name]\openssl\bin\openssl” sha1 -binary | “C:\Users\[my name]\openssl\bin\openssl” base64
I also get the same hash key [keyhash2=]
when i put my debug.keystore file in this cool program to get the hash key for Facebook (https://www.androidfilehost.com/?fid=95864024717072835). So the key i get must be good...
So I put in https://developers.facebook.com/apps/[my app id]/settings/ the hash key [keyhash2=]
and still got the above error. I put even both hash keys, the one i get with cmd and the one i see displayed in the error (includes the = sign) and still i have the same error. Does anyone know why?
I also see in facebook it is named key hash and in the cmd it is named hash key. I guess it is the same thing...
The solution: 1. the key has generated from windows is incorrect, either use the key hash that FB uses in the error, or get the same key hash by using the code i pasted below + 2. if you use Firebase, you need to introduce the OAuth redirect URI from Firebase (go to your Firebase Project, then Authentication, Sign In Method, then Facebook and you find there this URL). Then go to developers.facebook.com to your account, then Add a new Product, then choose Facebook Login, add there your link from Firebase and set Embedded Browser OAuth Login On (very important - this is the reason why it failed for me)
private void printKeyHash() {
// Add code to print out the key hash
try {
PackageInfo info = getPackageManager().getPackageInfo("**YOUR PACKAGE NAME**", 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) {
Log.e("KeyHash:", e.toString());
} catch (NoSuchAlgorithmException e) {
Log.e("KeyHash:", e.toString());
}
}
dont forget to call printKeyHash() from your MainActivity class. your code will be then displayed in adb logcat.