4

我现在真的很困惑。我尝试从我的应用程序登录 Facebook。当没有安装本机 FB 应用程序时,这可以正常工作。我得到了访问令牌并且可以使用它。但是,如果设备已经安装了 facebook 应用程序并且应用程序在登录请求上启动,我没有获得访问令牌,但出现以下异常

11-11 11:10:50.510: W/System.err(19215): com.facebook.FacebookAuthorizationException: UnknownError: ApiException:Key hash Djug8pU5w1DRPIxRaRf2N-4JniU does not match any stored key hashes.
11-11 11:10:50.510: W/System.err(19215):    at com.facebook.Session.handleAuthorizationResult(Session.java:1078)
11-11 11:10:50.510: W/System.err(19215):    at com.facebook.Session.onActivityResult(Session.java:554)
11-11 11:10:50.510: W/System.err(19215):    at com.lochmann.fb.viergewinntmultiplayer.MainActivity.onActivityResult(MainActivity.java:266)
11-11 11:10:50.510: W/System.err(19215):    at android.app.Activity.dispatchActivityResult(Activity.java:5322)
11-11 11:10:50.510: W/System.err(19215):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3363)
11-11 11:10:50.510: W/System.err(19215):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3410)
11-11 11:10:50.510: W/System.err(19215):    at android.app.ActivityThread.access$1100(ActivityThread.java:141)
11-11 11:10:50.510: W/System.err(19215):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1304)
11-11 11:10:50.510: W/System.err(19215):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-11 11:10:50.510: W/System.err(19215):    at android.os.Looper.loop(Looper.java:137)
11-11 11:10:50.510: W/System.err(19215):    at android.app.ActivityThread.main(ActivityThread.java:5103)
11-11 11:10:50.510: W/System.err(19215):    at java.lang.reflect.Method.invokeNative(Native Method)
11-11 11:10:50.510: W/System.err(19215):    at java.lang.reflect.Method.invoke(Method.java:525)
11-11 11:10:50.510: W/System.err(19215):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
11-11 11:10:50.510: W/System.err(19215):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-11 11:10:50.510: W/System.err(19215):    at dalvik.system.NativeStart.main(Native Method)
11-11 11:10:50.510: W/System.err(19215): com.facebook.FacebookAuthorizationException: UnknownError: ApiException:Key hash Djug8pU5w1DRPIxRaRf2N-4JniU does not match any stored key hashes.
11-11 11:10:50.510: W/System.err(19215):    at com.facebook.Session.handleAuthorizationResult(Session.java:1078)
11-11 11:10:50.510: W/System.err(19215):    at com.facebook.Session.onActivityResult(Session.java:554)
11-11 11:10:50.515: W/System.err(19215):    at com.lochmann.fb.viergewinntmultiplayer.MainActivity.onActivityResult(MainActivity.java:266)
11-11 11:10:50.515: W/System.err(19215):    at android.app.Activity.dispatchActivityResult(Activity.java:5322)
11-11 11:10:50.515: W/System.err(19215):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3363)
11-11 11:10:50.515: W/System.err(19215):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3410)
11-11 11:10:50.515: W/System.err(19215):    at android.app.ActivityThread.access$1100(ActivityThread.java:141)
11-11 11:10:50.515: W/System.err(19215):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1304)
11-11 11:10:50.515: W/System.err(19215):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-11 11:10:50.520: W/System.err(19215):    at android.os.Looper.loop(Looper.java:137)
11-11 11:10:50.525: W/System.err(19215):    at android.app.ActivityThread.main(ActivityThread.java:5103)
11-11 11:10:50.525: W/System.err(19215):    at java.lang.reflect.Method.invokeNative(Native Method)
11-11 11:10:50.525: W/System.err(19215):    at java.lang.reflect.Method.invoke(Method.java:525)
11-11 11:10:50.525: W/System.err(19215):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
11-11 11:10:50.525: W/System.err(19215):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-11 11:10:50.525: W/System.err(19215):    at dalvik.system.NativeStart.main(Native Method)

我真的认为我得到了正确的哈希键,因为:

public static String getKeyHash(Context context) {
    String returner = "";
    try {
        PackageInfo info = context.getPackageManager().getPackageInfo(
                "com.lochmann.fb.viergewinntmultiplayer", PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            returner = Base64.encodeToString(md.digest(), Base64.DEFAULT);
            Log.e("MY KEY HASH:",
                    Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    } catch (NameNotFoundException e) {
        e.printStackTrace();
        Log.e("ERROR", "NO NAME");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        Log.e("ERROR", "NO ALGO");

    }
    return returner;
}

返回11-11 11:10:42.445: E/MY KEY HASH:(19215): 2jmj7l5rSw0yVb/vlWAYkK/YBwk=

我在 FB 后端的设置如下所示:

在此处输入图像描述

有人对我有提示吗,我做错了什么或者我可以尝试什么?

提前致谢。

4

1 回答 1

2

如果您在活动中调用该方法,它总是返回错误的密钥哈希 [2jmj7l5rSw0yVb/vlWAYkK/YBwk=]。尝试在您的活动(oncreate)中打印它。实际上不知道为什么,但它对我有用。希望这可以帮助某人..

于 2013-11-15T23:33:13.803 回答