React Native FBSDK Invalid key hash. Keyhash has been added to developer.facebook and app is live

Viewed 6432

First of all, I know this is a duplicate of other threads and questions, since yesterday I think I've read them all.

Now, I'm trying to login using facebook on a React Native app, for now I'm just running it on android. The very first time I tested it, it worked.

I have added the key that the phone is showing in the error to developer.facebook.com, I changed my app to live in there as well and I even trie the code that people pasted on the older posts:

    try {
    PackageInfo info = getPackageManager().getPackageInfo(
                "com.blabla", 
                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 (NameNotFoundException e) {

} catch (NoSuchAlgorithmException e) {

}

This is the code I'm using for the login itself:

LoginManager.logInWithReadPermissions(['public_profile', 'email', 'user_likes']).then({
        function(result) {
            if (result.isCancelled) {
                alert('Login was cancelled');
            } else {
                AccessToken.getCurrentAccessToken().then((accessTokenData) => {
                    const credential = firebase.auth.FacebookAuthProvider.credential(accessTokenData.accessToken);

                    firebase.auth().signInWithCredential(credential).then((result) =>{
                        alert('Inicio de sesión exitoso');
                    }, (error)=>{
                        console.log(error)
                    })
                });
            }
        },
        function(error) {
            alert('Login failed with error: ' + error);
        }
    })
}

I'm getting this error:

Running on real device

At this point any help will be much appreciated, I'm quite desperate.

2 Answers

I have the same problem. On virtual devices everything is working well, but on real phone it didn't work, while I didn't add hash key from error message. I know that problem is in Facebook app which is instaled on my phone, it change hash key from my app on it own hash key when I'm trying to login in my app.

I got the same problem.

The answer is, the key hash always change in develop stage, for that reason we need to create another key hash when you are gonna move to production.

I saw this facebook developers tutorial, and now it's working for me.

https://developers.facebook.com/docs/android/getting-started/#release-key-hash

just try to run the next command and the keystore is gonna give you the production hashKey.

keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64

This command works really well on macOS.

Just use the same keyStore to sign your compiled APK.

Let me know if it works for you.

Related