简体   繁体   English

如果安装了 Native Facebook 应用,则无法使用 SDK 登录 Facebook

[英]Can't login to Facebook using SDK if Native Facebook app is installed

I have been integrated Facbook SDK in my app and all works, before i published it in Play store.在将 Facbook SDK 发布到 Play 商店之前,我已将 Facbook SDK 集成到我的应用程序和所有作品中。 When i published the app it no longer login to Facebook if there is Facebook app installed.当我发布应用程序时,如果安装了 Facebook 应用程序,它将不再登录 Facebook。

The error is:错误是:

com.facebook.http.protocol.ApiException: Key hash xxxxxxxxxxxxx does not match any stored key hashes.

But i saved this new key hash and the old one(debug version) in to my Facebook app settings.但是我将这个新的密钥哈希和旧的(调试版本)保存到我的 Facebook 应用程序设置中。

This is happening only when there is installed Facebook app in the device, if there is not i haven't this problem.仅当设备中安装了 Facebook 应用程序时才会发生这种情况,如果没有,我就没有这个问题。

I found the bug.我发现了这个错误。 Facebook showing wrong key-hash in Error Stack trace. Facebook 在错误堆栈跟踪中显示错误的密钥哈希。

Facebook somehow replacing characters. Facebook 以某种方式替换了字符。 For my case: i changed '-' to '+' and added '=' at the end of the key and its work for me.对于我的情况:我将“-”更改为“+”并在键的末尾添加了“=”及其对我的工作。

For 100% safety use this code in onCreate() to generate your key-hash.为了 100% 安全,在 onCreate() 中使用此代码来生成您的密钥哈希。

    private void generateHashKey() {
    // Add code to print out the key hash
    try {
        PackageInfo info = getPackageManager().getPackageInfo(
                "your.package.name", PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            System.out.println("KeyHash:" + Base64.encodeToString(md.digest(),Base64.DEFAULT));
        }
    } catch (NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM