Android Hash key changes in Facebook app

2020-06-06 07:16发布

I'm trying to put my debbug hash key, which is : "e3U9nzK7A8gyWoCiNUZQA/C+bZI=". But every time i put it inside the key hash section on my Facebook App it changes to "e3U9nzK7A8gyWoCiNUZQA%2FC%2BbZI%3D" automatically, making my app useless. I used two methods to get this key, and it returned the same : keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64

and :

 private void getAppKeyHash() {
    try {
        PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md;

            md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            String something = new String(Base64.encode(md.digest(), 0));
            Log.d("Hash key", something);
        } 
    }
    catch (NameNotFoundException e1) {
        // TODO Auto-generated catch block
        Log.e("name not found", e1.toString());
    }

    catch (NoSuchAlgorithmException e) {
        // TODO Auto-generated catch block
        Log.e("no such an algorithm", e.toString());
    }
    catch (Exception e){
        Log.e("exception", e.toString());
    }

}

2条回答
手持菜刀,她持情操
2楼-- · 2020-06-06 07:38

I have the same problem, and realised this is a bug on facebook´s end. See link. Very anoying.

Edit

The only working solution (but ugly) until it is solved seems to be to force login through web interface, since SSO is the one using the hashkey.

If using the login-button:

LoginButton authButton = (LoginButton) view.findViewById(R.id.authButton);
authButton.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);

Source: Android - Force Facebook connection - Stack Overflow

Edit 2

It can be solved though; I asked a friend (over Skype, he´s on a mac) to add them for me. And he managed to get it right (but I do not know how).

Edit 3

Now this issue seems to have solved itself for me. Entered hashkeys no longer gets rewritten. Whether it is solved by fb-team or just required a computer restart from me I do not know.

查看更多
▲ chillily
3楼-- · 2020-06-06 07:43

Try out this

 try {
                PackageInfo info = getPackageManager().getPackageInfo(com.domain,
                        PackageManager.GET_SIGNATURES);
                for (Signature signature : info.signatures) {
                    MessageDigest md = MessageDigest.getInstance("SHA");
                    md.update(signature.toByteArray());
                    Log.i("PXR", com.domain.Base64.encodeBytes(md.digest()));
                }
            } catch (NameNotFoundException e) {
            } catch (NoSuchAlgorithmException e) {
            }
查看更多
登录 后发表回答