skip to Main Content

After went though Getting Started FaceBook API, I get an error message after pressing in Android app the Login button:

Invalid key hash. The key hash does not match ..

None of the existing SO accepted answers were useful.

When generating the hash which password should I fill? Or an arbitrary password is ok?

I also tryed to fill in the hash key in error message into Facebook site, but it did not help.

I am using mac.

2

Answers


  1. Get the keyhash generated by below code and put that keyhash into your facebook app,call this method in your Login Activity and get the keyhash from Logcat.

     try {
            PackageInfo info = getPackageManager().getPackageInfo(
                    "packagename",
                    PackageManager.GET_SIGNATURES);
            for (android.content.pm.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) {
    
     }
    
    Login or Signup to reply.
  2. which OS you use?
    In case you use windows:

    1. go to your jdk/bin folder (usually in program files).
    2. copy the path.
    3. enter cmd.
    4. enter: cd {here paste the path}.
    5. search for your .android folder in your computer (usually in C:Usersname)
    6. copy the path.
    7. now, enter this in cmd:

    keytool -exportcert -alias androiddebugkey -keystore {path from
    6}.androiddebug.keystore | openssl sha1 -binary | openssl base64

    1. password: android
    2. copy the code and use it in facebook web.

    MAC:

    in section 7:

    keytool -exportcert -alias androiddebugkey -keystore
    ~/.android/debug.keystore | openssl sha1 -binary | openssl base64

    don’t forget to add in your activity:

    @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            callbackManager.onActivityResult(requestCode, resultCode, data);
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search