19

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?

leojg
  • 1,156
  • 3
  • 16
  • 40

8 Answers8

60

I spent a full day trying to figure out why this wasn't working...

When generating the hash key for production you need to use openssl-0.9.8e_X64.zip on windows, you cannot use openssl-0.9.8k_X64.zip

The versions produce different hash keys, for some reason 9.8k does not work correctly... 9.8e does

Reference

RevanthKrishnaKumar V.
  • 1,855
  • 1
  • 21
  • 34
Milk Man
  • 1,256
  • 13
  • 21
  • I believe this answer to be incorrect. There is nothing in the data in the question that suggests there is any issue with OpenSSL versions, and you have done nothing here to explain why that might be related. You *might* simply be responding to the title of the question, but you really need to read the details. – Andrew Barber Aug 19 '14 at 14:03
  • 2
    Perfect! I genereted using `openssl-0.9.8k_X64.zip `, then I use `openssl-0.9.8e_X64.zip` and it worked! – rsicarelli Sep 17 '14 at 21:42
  • 2
    AMAZING !! I wanted to give you +10. Thanks a lot. Who is supposed to know such thing? – gprathour Oct 07 '14 at 19:17
  • 2
    +100 This should be the accepted answer. Incredible, this. Facebook may want to switch to using the SHA1 fingerprint to avoid such confusion and use the key without running it through SSL. – Oliver Hausler Feb 14 '15 at 18:01
  • 2
    Nice answer. Really helped to me lot. I used openssl-0.9.8e_WIN32 for Windows 32 bit. It is working nicely. – Thirumalvalavan May 15 '15 at 13:27
  • 2
    If I didn't find your answer there is no telling how long I would have still been on this issue. – Syclone Mar 13 '16 at 04:42
  • 2
    Thank you so much! – Kirill Starostin Jul 06 '18 at 06:28
  • 2
    +1 I should have just downloaded the latest version. You can find windows binaries here https://wiki.openssl.org/index.php/Binaries Checking the hashes the 0.9.8e gives the same result as 1.0.2.q no idea why openssl-0.9.8k is different. – Fox Alex Apr 07 '19 at 08:30
42

You followed the steps that facebook provides for the creation of a login application?

You need a 'Production keyhash' obtained starting your release keystore:

From comand line:

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

And add this key on facebook app page options.

More information: Facebook docs

RevanthKrishnaKumar V.
  • 1,855
  • 1
  • 21
  • 34
Ramon Vicente
  • 761
  • 8
  • 12
  • 2
    what is release key alias – Satheesh Mar 09 '14 at 11:01
  • 7
    Note to others: do NOT use identical password and alias name. keytool does not give anything after password input if you have same alias name and password. To make it work, just recreate key file with different alias and password. – Youngjae Jun 13 '14 at 03:21
21

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.

patrickfdsouza
  • 747
  • 6
  • 17
  • 1
    this method is wrong. the key hash you get is for debug and not for the release version. – Qin Zhengquan Oct 19 '14 at 16:23
  • 1
    It worked for me. you need to sign your apk with release key and use the above said code to print your release Key hash and update it with your FB app. – Appbrain Oct 29 '14 at 09:43
  • NOTE: writing this line Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT)); more than once will give you different keys, only consider first key. – Appbrain Oct 29 '14 at 13:01
  • 1
    Worked for me. For those it doesn't work follow these step > add above in code > generate signed apk > install app through apk > getHash key > put has key in release key on facebook getstarted – Ajeet Jul 02 '15 at 11:35
  • You may look at this answer if keytool generates "wrong" key: http://stackoverflow.com/questions/27788884/invalid-key-hash-the-key-hash-does-not-match-android-fb-login – Ognyan Sep 26 '15 at 11:55
  • @patrickfdsouza I used your code it gives me exactly same keyhash that i got using terminal by this command `keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64` – Zeeshan Dec 31 '15 at 22:58
  • I am still getting keyhash does not match any stored key hash – Zeeshan Dec 31 '15 at 23:00
  • 1
    for many updates I'm generating hash key like this.What's happened to me is, For every version update hash key is changing.So everytime you have to check and update the hash key. – Stephen Aug 29 '16 at 05:22
13

You can also just take the missing hash from the stack trace of the ApiException: Key hash XXXXXXX does not match any stored key hashes. There you have it already, only missing the =at the end. So take XXXXXXX=.

Micky
  • 5,578
  • 7
  • 31
  • 55
5

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

Satheesh
  • 723
  • 7
  • 18
0

Above solutions are correct to a point. But if someone still faces an issue . Delete the key from developer profile and add it again writing= at the end and press enter . You have to add key in both settings and developer.

I was facing issues with app release to google play and using release key

Prayag
  • 331
  • 2
  • 9
  • Please explain fully how you resolved the problem, as if none of the other answers are here so that your answer alone is enough to resolve the problem. – SuperBiasedMan Jun 17 '15 at 11:17
0

I solved the issue in the simple way..

1)Frist Logout from the FaceBook app.

2)Open the Appplication which you have developed when cilck to login it will show the haskkey not mathcing.

3)Generate the SHA1 signing report in (Right Side Tab android studio) Gradle-->Task-->android->signing Report .(HEXA String)

4)Convert that to base 64.(Link) 5)Copy the output and past in the FaceBook developer page..


vinay shetty
  • 895
  • 1
  • 9
  • 15
-1

please check point no. 9 on Enable Single Sign On for Your App

Enable Single Sign On Enable single sign on for your app by setting Single Sign On to Yes below. YesNo Single Sign On

Ram Singh
  • 6,664
  • 35
  • 100
  • 166
kshitij
  • 135
  • 1
  • 1
  • 8