0

There is a facebook login button in my android app. I can login using that button. Button only one time I can login using facebook login button. I failed to login second time after succesfully logged out.This is the login response I got

Facebook ErrorInvalid key hash. The key hash HG2kYV1on+6yY1J7stl4KGrNsPA= does not match any stored key hashes. Configure your app key hashes at https://developers.facebook.com/apps/596405140754842/

But I logged in after copying that hash keys to stored keyhashes in my facebook devolopers page. When I install this app on another phone same problem occured.I solved it by copying that invalid hash key to stored hash keys in my facebook developers page. I also installed my app on phones without facebook application. In that case a new popup window comes asking email and facebook password. I can login and logout any number of times on those phones

But I need facebook login working on phones with facebook application without coping hash key for every phone

User 1278
  • 177
  • 2
  • 2
  • 8
  • 2
    Possible duplicate of [Facebook android app error : Invalid key hash](http://stackoverflow.com/questions/30934225/facebook-android-app-error-invalid-key-hash) – Shrenik Shah Mar 08 '17 at 07:23

1 Answers1

1

Create two keyHashes

  1. One using the command prompt:

    $ keytool -exportcert -alias androiddebugkey -keystore "C:\Documents and Settings\Administrator.android\debug.keystore" | "C:\OpenSSL\bin\openssl" sha1 -binary |"C:\OpenSSL\bin\openssl" base64
    
  2. using the code below:

    private String getAppKeyHash() {
      try {
        PackageInfo info = getPackageManager().getPackageInfo(
                getPackageName(), PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md;
    
            md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            String something = new String(Base64.encode(md.digest(), 0));
            return something;
    
        }
    } catch (Exception e) {
        Log.e("exception", e.toString());
    }
    return null;
    

    }

add both the key Hases in Facebook developers application.

This will work.

mohitum
  • 936
  • 2
  • 12
  • 26