Android Facebook Integration Invalid Key hash error on Android device but working fine on Emulator

百般思念 提交于 2020-01-01 15:25:00

问题


When I run my Android app in my android device it was working fine when I clicked first time on Continues with Facebook button.When i try to login again after logged out it is showing an error "Invalid Key has" The key has does not match any stored key hash. I have already regenerated key hash and replaced new key on facebook. bUt still did not get result.

First time I had easily logged-in, But after logged out again I'm trying to Continues with Facebook but it is showing an error message "Invalid Key has":

But the same application is running perfectly fine on Emulator. why it is not working on my devices?


回答1:


Hi Put this code in any reachable activity's onCreate method to print the hash key in the console and update that hash key in your facebook linked account with the application.

try {
            PackageInfo info = getPackageManager().getPackageInfo(
                    "com.facebook.samples.loginhowto", 
                    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 (NoSuchAlgorithmException e) {

        }



回答2:


Here is what you need to do -

Download openSSl from Code Extract it. create a folder- OpenSSL in C:/ and copy the extracted code here.

detect debug.keystore file path. If u didn't find, then do a search in C:/ and use the Path in the command in next step.

detect your keytool.exe path and go to that dir/ in command prompt and run this command in 1 line-

$ keytool -exportcert -alias androiddebugkey -keystore "C:\Documents and Settings\Administrator.android\debug.keystore" | "C:\OpenSSL\bin\openssl" sha1 -binary |"C:\OpenSSL\bin\openssl" base64

it will ask for password, put android that's all. u will get a key-hash



来源:https://stackoverflow.com/questions/47345521/android-facebook-integration-invalid-key-hash-error-on-android-device-but-workin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!