Facebook API login fails with FB app installed on phone

17,812

Solution 1

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.

Solution 2

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

Solution 3

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();

Solution 4

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 ....

Solution 5

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..

Share:
17,812
virusss8
Author by

virusss8

By day: grinder By night: sleepy ninja

Updated on June 05, 2022

Comments

  • virusss8
    virusss8 almost 2 years

    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
    virusss8 almost 12 years
    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?
  • Siddharth Lele
    Siddharth Lele almost 12 years
    @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.
  • virusss8
    virusss8 almost 12 years
    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 facebook.com/developers but I have never set that key anywhere. What key is that???
  • Siddharth Lele
    Siddharth Lele almost 12 years
    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
    Siddharth Lele almost 12 years
    Anytime fella. ;-) Glad I could help.
  • anddev
    anddev almost 11 years
    @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.
  • Siddharth Lele
    Siddharth Lele almost 11 years
    @anddev: Unfortunately, that does not work with the new SDK. Use the method listed under Solution 1 here: stackoverflow.com/a/13283088/450534. That will do the job.
  • anddev
    anddev almost 11 years
    @IceMAN I got the hashkey. Thanks. Can you pleas help me in my query? I posted my question here:stackoverflow.com/questions/17464648/… It is very greatful if you will give me the solution please help me .
  • Cruceo
    Cruceo over 10 years
    Why would you post the wrong in text and not the right? I almost used it lol but thanks for the link to the right one
  • AlexAndro
    AlexAndro over 10 years
    @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?
  • Siddharth Lele
    Siddharth Lele over 10 years
    @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.
  • Cam Connor
    Cam Connor over 10 years
    THANK YOU just spent the last 3 hours trying to figure this out
  • Matan Dahan
    Matan Dahan about 7 years
    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..