android – Facebook SDK 3.5通过App登录不起作用

我现在真的很困惑.我尝试从我的应用程序登录Facebook.当没有安装本机FB应用程序时,这很好.我得到了Acces Token并且可以使用它.但是如果设备已经安装了facebook应用程序并且应用程序在登录请求中启动,我就不会获得具有以下异常的Acces令牌

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)

我确实认为我得到了正确的Hash密钥,因为:

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 Backend中的我的设置如下所示:

有没有人暗示我,我做错了什么或我能尝试什么?

提前致谢.

最佳答案 如果你从活动中调用该方法,它将返回错误的密钥哈希[2jmj7l5rSw0yVb / vlWAYkK / YBwk =].尝试在您的活动中打印它(oncreate).其实不知道为什么,但它对我有用.希望这有助于某人..

点赞