3

I uploaded my fully working app on Google Play and when download it from there, facebook login doesn't work!! I properly configure my facebook app and works with eclipse environment. After searching, it can be done due to facebook key hashes. However, I obtained it like:

How to generate Key Hash for facebook SDK In Mac

Seems that a key hash for distribution must be also obtained... but how? Thank you.

Community
  • 1
  • 1
Jaume
  • 3,318
  • 16
  • 50
  • 108
  • That is expected. You generated the Key Hash for the debug key while testing using Eclipse. You will also need to generate a Key Hash for your app using the release key, the one that you signed your app with for deploying on Google Play. Do that, and you will be good to go. ;-) – Siddharth Lele Jul 21 '13 at 09:02
  • 1
    @SiddharthLele Perhaps you should post that as an answer. – tbodt Jul 21 '13 at 09:09

3 Answers3

3

Alternative 1:

Use this with the app signed with your release key. Not the one that is deployed from Eclipse.

Run this piece of code in the first Activity of your app:

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.e("FACEBOOK APP SIGNATURE", Base64.encodeToString(md.digest(), Base64.DEFAULT));
    }
} catch (Exception e) {
    // TODO: handle exception
    e.printStackTrace();
}

This line: Log.e("FACEBOOK APP SIGNATURE", Base64.encodeToString(md.digest(), Base64.DEFAULT)); will log the Key Hash in DDMS.

Alternative 2:

  1. Download OpenSSl for Windows and extract the .zip to a simple location like: c:\openssl with all the contents of the zip extracted in this folder's root.
  2. Copy your signing key file to your JRE installation's bin folder. For example, in my case: C:\Program Files\Java\jre7\bin
  3. While in the bin folder where you copied the signing key, Press SHIFT+ Right Click -> Open command window here.
  4. Run this command: keytool -exportcert -alias YOUR_ALIAS -keystore YOUR_SIGNING_KEY > c:\openssl\bin\debug.txt
  5. Enter your password for the signing key
  6. Now, navigate to the c:\openssl\bin folder and type in the following commands:

openssl sha1 -binary debug.txt > debug_sha.txt

And then,

openssl base64 -in debug_sha.txt > debug_base64.txt

Done! The debug_base64.txt contains your Key Hash. Copy this in your app console and you are all set.

In my experiece, both the methods have given me the correct Key Hash. However, in a few cases (rather random ones), the first alternative did not give the correct Key Hash while the second alternative has always worked. See which works for you.

Siddharth Lele
  • 26,905
  • 15
  • 91
  • 144
  • for alternative1, it returns me key hash that I already have, debug one!but I need distribution one. I have apk file signed but how to acces to it in order to get key hash? – Jaume Jul 21 '13 at 10:03
  • @Jaume: Have you exported a new Signed APK with the release key? You will need to do that, then manually copy that APK on your device, install from a File Manager and then run the app with the device connected to the computer and the DDMS view open. – Siddharth Lele Jul 21 '13 at 10:05
  • @Jaume: I suspect it still gives you the old key hash because you haven't exported a signed APK and installed that. – Siddharth Lele Jul 21 '13 at 10:06
  • well I did it with signed apk and it returns a different key hash. This seems to be what I was expecting and then, I added to facebook key hashes on my app. However, still doing the same... Should I modify something else or am I missing anything? – Jaume Jul 21 '13 at 17:20
  • problem was on log key hash. I don't know why but must be saved first as string and then log it. After that, solved!! many thanks for "alternative 1" code!! really thankfull – Jaume Jul 21 '13 at 19:15
1

While generating release Hash key, Note this

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.

OR

Use this below flow

This is how I solved this problem Download your APK to your PC in java jdk\bin folder in my case C:\Program Files\Java\jdk1.7.0_121\bin go to java jdk\bin folder and run cmd then copy the following command in your cmd

keytool -list -printcert -jarfile yourapkname.apk

Copy the SHA1 value to your clip board like this CD:A1:EA:A3:5C:5C:68:FB:FA:0A:6B:E5:5A:72:64:DD:26:8D:44:84 and open Hex To Base 64 to convert your SHA1 value to base64.

Thamim
  • 298
  • 3
  • 12
0

Try this solution, for me I was getting the same error, but working fine now after trying hours.

Login Error: There is an error in logging you into this application. Please try again later