我现在真的很困惑。我尝试从我的应用程序登录 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 后端的设置如下所示:
有人对我有提示吗,我做错了什么或者我可以尝试什么?
提前致谢。