Android Facebook SDK: Key hash does not match any

2020-02-07 16:26发布

My app uses facebook api for user login. On developing it works fine, but when I uploaded it to google play it stops working.

This is the error log:

12-10 20:20:02.488: W/fb4a(:<default>):BlueServiceQueue(17284): Exception during service
12-10 20:20:02.488: W/fb4a(:<default>):BlueServiceQueue(17284): com.facebook.http.protocol.ApiException: Key hash XXXXXXX does not match any stored key hashes.
12-10 20:20:02.488: W/fb4a(:<default>):BlueServiceQueue(17284):     at com.facebook.http.protocol.ApiResponseChecker.b(ApiResponseChecker.java:83)
12-10 20:20:02.488: W/fb4a(:<default>):BlueServiceQueue(17284):     at com.facebook.http.protocol.ApiResponseChecker.a(ApiResponseChecker.java:162)
12-10 20:20:02.488: W/fb4a(:<default>):BlueServiceQueue(17284):     at com.facebook.http.protocol.ApiResponse.g(ApiResponse.java:239)
12-10 20:20:02.488: W/fb4a(:<default>):BlueServiceQueue(17284):     at com.facebook.katana.server.protocol.AuthorizeAppMethod.a(AuthorizeAppMethod.java:272)
12-10 20:20:02.488: W/fb4a(:<default>):BlueServiceQueue(17284):     at com.facebook.katana.server.protocol.AuthorizeAppMethod.a(AuthorizeAppMethod.java:29)
12-10 20:20:02.488: W/fb4a(:<default>):BlueServiceQueue(17284):     at com.facebook.http.protocol.ApiResponseHandler.a(ApiResponseHandler.java:56)
12-10 20:20:02.488: W/fb4a(:<default>):BlueServiceQueue(17284):     at com.facebook.http.protocol.ApiResponseHandler.handleResponse(ApiResponseHandler.java:29)
12-10 20:20:02.488: W/fb4a(:<default>):BlueServiceQueue(17284):     at com.facebook.http.common.FbHttpRequestProcessor.a(FbHttpRequestProcessor.java:280)
12-10 20:20:02.488: W/fb4a(:<default>):BlueServiceQueue(17284):     at com.facebook.http.common.FbHttpRequestProcessor.a(FbHttpRequestProcessor.java:141)
12-10 20:20:02.488: W/fb4a(:<default>):BlueServiceQueue(17284):     at com.facebook.http.common.FbHttpRequestProcessor.b(FbHttpRequestProcessor.java:103)
12-10 20:20:02.488: W/fb4a(:<default>):BlueServiceQueue(17284):     at com.facebook.http.common.FbHttpRequestProcessor.a(FbHttpRequestProcessor.java:196)
12-10 20:20:02.488: W/fb4a(:<default>):BlueServiceQueue(17284):     at com.facebook.http.protocol.SingleMethodRunnerImpl.a(SingleMethodRunnerImpl.java:374)
12-10 20:20:02.488: W/fb4a(:<default>):BlueServiceQueue(17284):     at com.facebook.http.protocol.SingleMethodRunnerImpl.a(SingleMethodRunnerImpl.java:151)
12-10 20:20:02.488: W/fb4a(:<default>):BlueServiceQueue(17284):     at com.facebook.http.protocol.AbstractSingleMethodRunner.a(AbstractSingleMethodRunner.java:18)
12-10 20:20:02.488: W/fb4a(:<default>):BlueServiceQueue(17284):     at com.facebook.katana.server.handler.PlatformOperationHandler.c(PlatformOperationHandler.java:367)
12-10 20:20:02.488: W/fb4a(:<default>):BlueServiceQueue(17284):     at com.facebook.katana.server.handler.PlatformOperationHandler.a(PlatformOperationHandler.java:260)
12-10 20:20:02.488: W/fb4a(:<default>):BlueServiceQueue(17284):     at com.facebook.fbservice.service.BlueServiceQueue.e(BlueServiceQueue.java:299)
12-10 20:20:02.488: W/fb4a(:<default>):BlueServiceQueue(17284):     at com.facebook.fbservice.service.BlueServiceQueue.d(BlueServiceQueue.java:53)
12-10 20:20:02.488: W/fb4a(:<default>):BlueServiceQueue(17284):     at com.facebook.fbservice.service.BlueServiceQueue$3.run(BlueServiceQueue.java:230)
12-10 20:20:02.488: W/fb4a(:<default>):BlueServiceQueue(17284):     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
12-10 20:20:02.488: W/fb4a(:<default>):BlueServiceQueue(17284):     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
12-10 20:20:02.488: W/fb4a(:<default>):BlueServiceQueue(17284):     at com.facebook.common.executors.ListenableScheduledFutureImpl.run(ListenableScheduledFutureImpl.java:59)
12-10 20:20:02.488: W/fb4a(:<default>):BlueServiceQueue(17284):     at android.os.Handler.handleCallback(Handler.java:733)
12-10 20:20:02.488: W/fb4a(:<default>):BlueServiceQueue(17284):     at android.os.Handler.dispatchMessage(Handler.java:95)
12-10 20:20:02.488: W/fb4a(:<default>):BlueServiceQueue(17284):     at android.os.Looper.loop(Looper.java:137)
12-10 20:20:02.488: W/fb4a(:<default>):BlueServiceQueue(17284):     at android.os.HandlerThread.run(HandlerThread.java:61)
12-10 20:20:02.498: W/fb4a(:<default>):GDPDialog(17284): Failed to send
12-10 20:20:02.498: W/fb4a(:<default>):GDPDialog(17284): com.facebook.fbservice.service.ServiceException: API_ERROR: API_ERROR
12-10 20:20:02.498: W/fb4a(:<default>):GDPDialog(17284):    at com.facebook.fbservice.ops.BlueServiceOperation.c(BlueServiceOperation.java:640)
12-10 20:20:02.498: W/fb4a(:<default>):GDPDialog(17284):    at com.facebook.fbservice.ops.BlueServiceOperation.c(BlueServiceOperation.java:48)
12-10 20:20:02.498: W/fb4a(:<default>):GDPDialog(17284):    at com.facebook.fbservice.ops.BlueServiceOperation$2.run(BlueServiceOperation.java:605)
12-10 20:20:02.498: W/fb4a(:<default>):GDPDialog(17284):    at android.os.Handler.handleCallback(Handler.java:733)
12-10 20:20:02.498: W/fb4a(:<default>):GDPDialog(17284):    at android.os.Handler.dispatchMessage(Handler.java:95)
12-10 20:20:02.498: W/fb4a(:<default>):GDPDialog(17284):    at android.os.Looper.loop(Looper.java:137)
12-10 20:20:02.498: W/fb4a(:<default>):GDPDialog(17284):    at android.app.ActivityThread.main(ActivityThread.java:4998)
12-10 20:20:02.498: W/fb4a(:<default>):GDPDialog(17284):    at java.lang.reflect.Method.invokeNative(Native Method)
12-10 20:20:02.498: W/fb4a(:<default>):GDPDialog(17284):    at java.lang.reflect.Method.invoke(Method.java:515)
12-10 20:20:02.498: W/fb4a(:<default>):GDPDialog(17284):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
12-10 20:20:02.498: W/fb4a(:<default>):GDPDialog(17284):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
12-10 20:20:02.498: W/fb4a(:<default>):GDPDialog(17284):    at dalvik.system.NativeStart.main(Native Method)

Could it be that the key hash changed in some way?

8条回答
▲ chillily
2楼-- · 2020-02-07 17:16

This was giving the wrong key for me.

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

A workaround that worked for me was: 1. Put this code in your launching activity

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 (NameNotFoundException e) {
        Log.d("KeyHash:", e.toString());
    } catch (NoSuchAlgorithmException e) {
        Log.d("KeyHash:", e.toString());
    }
}
  1. Export the app for publishing on play store using the .keyStore
  2. Install the app before uploading to play store and run it and note the keyHash printed.
  3. Add the keyHash to the Facebook App.

Hope this helps someone.

查看更多
该账号已被封号
3楼-- · 2020-02-07 17:16

This is working fine to me

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

Where <RELEASE_KEY_ALIAS>is your Alias name while you create signed application.

enter image description here

And <RELEASE_KEY_PATH>is Location in the below picture And then enter the password is key create password in the below picture instead of android

enter image description here

查看更多
登录 后发表回答