Getting invalid android_key parameter error, after

2019-03-15 21:45发布

问题:

I have got the hash key from my debug store using

keytool -exportcert -alias androiddebugkey -keystore C:\Users\user.android\debug.keystore | openssl sha1 -binary | openssl enc -a -e

and pasted the key to Facebook App for Android and also enabled "Facebook Login" option.

When I first time log into my Android App, it shows me a permission dialog and after giving the permission, I am enable to get me details from Facebook.

But after that when i exit and the app and again open and try to login, it shows below screen.

I don't get this, if hash key is the issues, then why it works in first attempt.

I am using facebook sdk old version not the new 3.+ version.

回答1:

Solved the issues, added permission of "offline_access" and also the Hashkey should match the key which appears in error. Use "Key Hash" apk available at Easy Facebook SDK website, install it on phone to get the HASH KEY or use KEYTOOL plugin to get the SHA1 of your keystore and then convert it to base64 from here. and add this key to your register project.. :) Hope this helps @Pratick



回答2:

key hash generate via code and paste on facebook apps setting key hash . 100% will be solved . The code is

try {
        PackageInfo info = getPackageManager().getPackageInfo(
                "com.matainja.facebooklogin", 
                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) {

    } catch (NoSuchAlgorithmExceptio`enter code here`n e) {

    }

replace the package name .