1
votes

first of all: I've tried all purposed solutions up here on stackexchange. Not one worked so far.

So here's my problem:

I try to integrate a facebook login in my android app. I can “log in” at the first try (I get the opportunity to log in, but nothing happens). When I try it again, I get the following error: “invalid key hash. the key hash does not match any stored key hashes”

What I’ve done:

  • Implement all steps of the developer.facebook tutorial to get the login button
  • Create a development key (keytool -exportcert -alias androiddebugkey -keystore "%PATH%\debug.keystore" | "%PATH%\openssl" sha1 -binary |"%PATH%\openssl" base64) and added it
  • Create a release key (keytool -exportcert -alias android -keystore "%PATH%\debug.keystore" | "%PATH%\openssl" sha1 -binary |"%PATH%\openssl" base64) and added it
  • When I add my package name and my class name, I get the following message: “We were unable to verify your package namecom.example.facebooklogin on Google Play. Please double-check your package name before proceeding. If your app is not publicly listed on Google Play yet, you may safely ignore this warning.” – I ignore the message, because my app isn’t at google play (it’s my first testgame)

I’ve added this part in my onCreate, but nothing changes:

try {
        PackageInfo info = getPackageManager().getPackageInfo(
                "com.example.kndel.facebooklogin",
                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) {

    } catch (NoSuchAlgorithmException e) {

    }

What’s wrong?? I have no idea

1
Please paste your activity class where you using above code - rachar_P

1 Answers

0
votes

Add this function into your class,and call this function in oncreate methode,then generate signed apk (this function will return hash key for both mode bedbug and release) and run sign apk in your device and check log-cat, copy generated hash key to facebook developer console.

private void showHashKey()
{
    // Add code to print out the key hash
    try {
        PackageInfo info = getPackageManager().getPackageInfo(
                "com.kisan.kisan",
                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) {

    } catch (NoSuchAlgorithmException e) {

    }

}

Note : This function will return hash key for both mode bedbug and release.

Check facebook authentication,it will work fine