skip to Main Content

So I’ve implemented Facebook Login in my Android app for a while now, and it’s been working fine for months.

The problems began when I updated the SDK version to one of the latest (4.22.0). After this point, clicking the Facebook Login button just causes a brief attempt at logging in and then nothing. From the log I can see onCancel() in the FacebookCallback is being called but that’s it.

Everything works fine when I uninstall the Facebook app. I go through the web view login and then I’m able to proceed (onSuccess() is called).

I’ve tried reverting back to the SDK version I was using earlier, but no luck. I’ve checked that my KeyHashes match (both debug and release) what’s on the Facebook Developer Dashboard, and it does. My App ID matches too.’

I know that I’m logged out prior to attempting a login since I’m forcing a logout with LoginManager.

It’s very odd. I used the following code to generate my KeyHash:

try {
            PackageInfo info = getPackageManager().getPackageInfo(
                    "***.*****.************",
                    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 (PackageManager.NameNotFoundException e) {

        } catch (NoSuchAlgorithmException e) {

        }

3

Answers


  1. You need to have a signed aPK KeyHash so, make signed APk and that signed APK run in your device and get signed keyHash from debug log.that key hash update into your facebook developer console.

    Login or Signup to reply.
  2. Try to using that code for fackbook hash key generation.

     try {
                PackageInfo info = getPackageManager().getPackageInfo("enter your package", 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 (PackageManager.NameNotFoundException e) {
    
            } catch (NoSuchAlgorithmException e) {
    
            }
    
    Login or Signup to reply.
  3. I used following steps to generate a Key Hash for my app in facebook:

    1. First open a terminal in mac (open a command prompt in windows).
    2. Navigate in the terminal to the directory where your Android debug.keystore is stored. Mostly in Windows it will located under “/Users/user_name/.android/” and in Windows will be C:Documents and Settings.android).

    3. In mac – Type cd ~/.android and hit enter to go to .android directory

    4. Once you are in the “.android” directory, run the following command to get a debug key..
      keytool -exportcert -alias androiddebugkey -keystore debug.keystore | openssl sha1 -binary | openssl base64

    5. Use the same procedure to get the Release key. Just replace the command with the following and use your release key alias.
      keytool -exportcert -alias YOUR_RELEASE_KEY_ALIAS -keystore YOUR_RELEASE_KEY_PATH | “PATH FOR openssl.exe” sha1 -binary | openssl base64

    6. When it prompts you for a password, type android and hit Enter

    7. Copy the value printed in the terminal that ends with an “=” and paste it in the Key Hash field in Facebook. Then click the Save Changes button.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search