10

I am building an app, which is going to have support for facebook. I have downloaded facebook API and their sample called "Hackbook" from original Git repos. The problem is with login - if original FB app is not installed on phone, the login is going through custom dialog and everything works, but if FB app is installed, the Hackbook automatically redirect to original FB app, and then nothing happened. It's impossible to login. I have tested this on five different phones, and always was the same problem.

virusss8
  • 227
  • 1
  • 4
  • 18

5 Answers5

18

I had a similar problem. In my case, I had not created a hash key using my signing key. I just had the one hash key created using the debug.keystore default signing key.

As soon as i created a hash key using my app release signing key, that problem was sorted out. If you haven't already done this, create a new hash key using your signing key (for uploading on the market) and add that to your app's facebook control panel.

Hope this helps.

Siddharth Lele
  • 26,905
  • 15
  • 91
  • 144
  • I added that hash key into control panel, but problem is still here. Do I have to add hash key also into fb api somewhere? – virusss8 May 10 '12 at 08:27
  • 2
    @virusss8: You don't need to add the hashkey in your app. Follow this step and tell me the result. Open the Util class file in your facebook-sdk and change the 'private static boolean ENABLE_LOG = false' to 'true'. Now keep your phone connected to your development PC and run the app created using the signed apk and log in. Keep a DDMS window open and see if it generates an error. – Siddharth Lele May 10 '12 at 08:45
  • D/Facebook-authorize(25124): Login failed: invalid_key:Android key mismatch. Your key "*********real*key************" does not match the allowed keys specified in your application settings. Check your application settings at http://www.facebook.com/developers but I have never set that key anywhere. What key is that??? – virusss8 May 10 '12 at 09:48
  • That's the key you should put in the apps control panel. Copy the key shown in the log and replace the key you last put (using the signing key) with this one from the DDMS log. – Siddharth Lele May 10 '12 at 10:12
  • Anytime fella. ;-) Glad I could help. – Siddharth Lele May 10 '12 at 10:24
  • @UceMAN I am not able to found private static boolean ENABLE_LOG = false in my FacebookSDK Util class. I am using FacebookSDK 3.0.1. Can you please help me? I want to login my app with intalled Facebook application. And I am using appId which is made by release keystore. – anddev Jul 05 '13 at 05:38
  • 2
    @anddev: Unfortunately, that does not work with the new SDK. Use the method listed under _Solution 1_ here: http://stackoverflow.com/a/13283088/450534. That will do the job. – Siddharth Lele Jul 05 '13 at 06:14
  • @IceMAN I got the hashkey. Thanks. Can you pleas help me in my query? I posted my question here:http://stackoverflow.com/questions/17464648/how-to-get-default-facebook-app-login-session-in-to-our-application-in-android It is very greatful if you will give me the solution please help me . – anddev Jul 05 '13 at 06:33
  • @SiddharthLele Did you updated your apk on GooglePlay with a new one or just replaced the hashkey in your AppSettings on Facebook? I have just replaced the hashkey on Facebook, wait several minutes, tried again(with the app already published before) and still doesn't work? – AlexAndro Sep 08 '13 at 10:28
  • @AlexAndro: No need to update the APK. Just add the new Hash Key and it should be all good. As long as the correct signing key has been used for the app as well as the Hash Key, no need to update the APK. It does take a little time to filter down FB's system. In my experience, I had to wait almost 4 hours before an app of mine started to work properly. – Siddharth Lele Sep 08 '13 at 11:11
4

I have toiled for two days & got the solution at last, this is the WRONG way to get the hash key -

keytool -exportcert -alias *<your _alias_name>* -keystore *<key_store_path>* | [openssl_bin_directory]\openssl sha1 -binary | [openssl_bin_directory]\openssl base64

The right way is type these 3 lines, one at a time in cmd. After the first line, you'll be asked to insert the keystore password.

keytool -exportcert -alias *<your _alias_name>* -keystore *<key_store_path>* > [openssl_bin_directory]\debug.txt
[openssl_bin_directory]\openssl sha1 -binary [openssl_bin_directory]\debug.txt > [openssl_bin_directory]\debug_sha.txt
[openssl_bin_directory]\openssl base64 -in [openssl_bin_directory]\debug_sha.txt > [openssl_bin_directory]\debug_base64.txt

If you want to know details, the RIGHT way is described here -

http://facebook.stackoverflow.com/questions/13281913/app-is-misconfigured-for-facebook-login-with-release-key-hash

or here

Facebook Android Generate Key Hash

Community
  • 1
  • 1
Khobaib
  • 1,507
  • 2
  • 19
  • 29
1

Get you hash key using this function for both(debug and release apk) and put it in your app in developer.facebook.com/apps

private void calculateHashKey(String yourPackageName) {
    try {
        PackageInfo info = getPackageManager().getPackageInfo(
                yourPackageName,
                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) {
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
}

this help me a lot.. Hope this will help you too..

jignesh
  • 1,214
  • 1
  • 10
  • 22
1

I have fixed this issue . After getting Key hash by using keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64 I have logged in first time in release mode successfully... Then second time i got the common error Your key "*********real*key************" does not match the allowed keys specified in your application settings.

Just use the "*********real*key************" which Facebook gives in error message I logged in successfully now in release mode. So be sure while entering this key that you use the exact same key. The LETTERS I , small(L) i.e (l) will make you in trouble. I made two keys , in the first key I've used small(L) i.e (l) and in second key I've used I. and placed these keys in developer app.
It is working now ....

  • That was the exact problem in my case..the only solution that worked! and the part about small 'L' is correct, and also Big 'I' (which might look like a small 'L' in some fonts.. – Matan Dahan Apr 25 '17 at 12:02
1

In my case the problem was that the user-login gets cancelled when the facebook app is installed on the device even after generating right keys.

I added following line before login and it works great.

LoginManager.getInstance().logOut();
Akash Bisariya
  • 2,431
  • 1
  • 24
  • 39