android - 为什么Facebook身份验证SDK的行为方式如此不同,具体取决于其模式?
firebase firebase-authentication (4)
它说,在日志的顶部
Key hash GtvUdcOKFRAE0RY0LIw5veCA+M8= does not match any stored key hashes.
在构建发布时,您可能使用了错误的keyhash。 显然,当您使用 此链接中 讨论的错误keyhash时会发生此问题。
至于为什么它在WEB模式下工作,因为keyhash由SDK检查,因为你转到网页,你不会得到错误。 您正在调试模式和调试模式下运行密钥哈希可能是正确的,这可能是它在您的设备上工作的答案。
我在App Store中有一个Android应用程序。 它在后端使用Firebase,并通过Facebook(和Google)提供社交登录。
最近Facebook联系我,警告我,我的应用程序在通过Facebook登录时崩溃/无响应。 困惑,我开始进行一些测试。
我发现如果我在没有安装Facebook应用程序的情况下使用Facebook登录,一切都运行良好。 用户会看到一个浏览器窗口,可以登录,然后他们会被重定向回我的应用程序并且我有自己的身份。 当然,我在开发过程中发现了所有这些,但只是想确认事情仍然有效。
但是当我安装Facebook应用程序时(我在开发过程中忽略了一些事情),我发现它不再适用。 相反,用户将重定向到此页面:
对于搜索和辅助功能,此图像中的文字为:
登录错误:登录此应用程序时出错。 请稍后再试。
发生这种情况时我检查了日志,发现以下 可能 相关,但我不确定:
07-05 15:36:28.468 908 5828 I ActivityManager: START u0 {act=NATIVE_WITH_FALLBACK cmp=<<redacted>>/com.facebook.FacebookActivity (has extras)} from uid 10264
07-05 15:36:28.469 665 665 D QCOM PowerHAL: LAUNCH HINT: ON
07-05 15:36:28.470 665 665 D QCOM PowerHAL: Activity launch hint handled
07-05 15:36:28.495 4837 4837 W ActivityThread: handleWindowVisibility: no activity for token android.os.[email protected]
07-05 15:36:28.689 665 665 D QCOM PowerHAL: LAUNCH HINT: OFF
07-05 15:36:28.946 29406 4941 W fb4a.BlueServiceQueue: Exception during service
07-05 15:36:28.946 29406 4941 W fb4a.BlueServiceQueue: X.2LH: [code] 404 [message]: Key hash GtvUdcOKFRAE0RY0LIw5veCA+M8= does not match any stored key hashes. (404) [extra]: null
07-05 15:36:28.946 29406 4941 W fb4a.BlueServiceQueue: at X.1eL.C(:93)
07-05 15:36:28.946 29406 4941 W fb4a.BlueServiceQueue: at X.2sO.C(:26)
07-05 15:36:28.946 29406 4941 W fb4a.BlueServiceQueue: at X.CvC.umA(:38)
07-05 15:36:28.946 29406 4941 W fb4a.BlueServiceQueue: at X.2yi.handleResponse(:224)
07-05 15:36:28.946 29406 4941 W fb4a.BlueServiceQueue: at X.1dO.run(:71)
07-05 15:36:28.946 29406 4941 W fb4a.BlueServiceQueue: at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458)
07-05 15:36:28.946 29406 4941 W fb4a.BlueServiceQueue: at X.0r0.run(:2)
07-05 15:36:28.946 29406 4941 W fb4a.BlueServiceQueue: at X.1qG.run(:2)
07-05 15:36:28.946 29406 4941 W fb4a.BlueServiceQueue: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
07-05 15:36:28.946 29406 4941 W fb4a.BlueServiceQueue: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
07-05 15:36:28.946 29406 4941 W fb4a.BlueServiceQueue: at X.12V.run(:3)
07-05 15:36:28.946 29406 4941 W fb4a.BlueServiceQueue: at X.1xB.run(:12)
07-05 15:36:28.946 29406 4941 W fb4a.BlueServiceQueue: at java.lang.Thread.run(Thread.java:764)
07-05 15:36:28.981 908 8581 I ActivityManager: START u0 {cmp=com.facebook.katana/.ProxyAuth (has extras)} from uid 10264
07-05 15:36:28.982 665 665 D QCOM PowerHAL: LAUNCH HINT: ON
07-05 15:36:28.983 665 665 D QCOM PowerHAL: Activity launch hint handled
07-05 15:36:29.022 29406 29406 W ActivityThread: handleWindowVisibility: no activity for token android.os.[email protected]
07-05 15:36:29.037 29406 29406 E Instrumentation: Uninitialized ActivityThread, likely app-created Instrumentation, disabling AppComponentFactory
07-05 15:36:29.037 29406 29406 E Instrumentation: java.lang.Throwable
07-05 15:36:29.037 29406 29406 E Instrumentation: at android.app.Instrumentation.getFactory(Instrumentation.java:1224)
07-05 15:36:29.037 29406 29406 E Instrumentation: at android.app.Instrumentation.newActivity(Instrumentation.java:1215)
07-05 15:36:29.037 29406 29406 E Instrumentation: at X.05O.newActivity(:3382)
07-05 15:36:29.037 29406 29406 E Instrumentation: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2869)
07-05 15:36:29.037 29406 29406 E Instrumentation: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3086)
07-05 15:36:29.037 29406 29406 E Instrumentation: at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
07-05 15:36:29.037 29406 29406 E Instrumentation: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
07-05 15:36:29.037 29406 29406 E Instrumentation: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
07-05 15:36:29.037 29406 29406 E Instrumentation: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
07-05 15:36:29.037 29406 29406 E Instrumentation: at android.os.Handler.dispatchMessage(Handler.java:106)
07-05 15:36:29.037 29406 29406 E Instrumentation: at android.os.Looper.loop(Looper.java:193)
07-05 15:36:29.037 29406 29406 E Instrumentation: at android.app.ActivityThread.main(ActivityThread.java:6718)
07-05 15:36:29.037 29406 29406 E Instrumentation: at java.lang.reflect.Method.invoke(Native Method)
07-05 15:36:29.037 29406 29406 E Instrumentation: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
07-05 15:36:29.037 29406 29406 E Instrumentation: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
07-05 15:36:29.045 908 2933 I ActivityManager: START u0 {flg=0x2000000 cmp=com.facebook.katana/com.facebook.gdp.ProxyAuth (has extras)} from uid 10262
07-05 15:36:29.047 665 665 D QCOM PowerHAL: LAUNCH HINT: ON
07-05 15:36:29.068 29406 29406 W ActivityThread: handleWindowVisibility: no activity for token android.os.[email protected]
07-05 15:36:29.069 29406 29406 E Instrumentation: Uninitialized ActivityThread, likely app-created Instrumentation, disabling AppComponentFactory
07-05 15:36:29.069 29406 29406 E Instrumentation: java.lang.Throwable
07-05 15:36:29.069 29406 29406 E Instrumentation: at android.app.Instrumentation.getFactory(Instrumentation.java:1224)
07-05 15:36:29.069 29406 29406 E Instrumentation: at android.app.Instrumentation.newActivity(Instrumentation.java:1215)
07-05 15:36:29.069 29406 29406 E Instrumentation: at X.05O.newActivity(:3382)
07-05 15:36:29.069 29406 29406 E Instrumentation: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2869)
07-05 15:36:29.069 29406 29406 E Instrumentation: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3086)
07-05 15:36:29.069 29406 29406 E Instrumentation: at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
07-05 15:36:29.069 29406 29406 E Instrumentation: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
07-05 15:36:29.069 29406 29406 E Instrumentation: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
07-05 15:36:29.069 29406 29406 E Instrumentation: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
07-05 15:36:29.069 29406 29406 E Instrumentation: at android.os.Handler.dispatchMessage(Handler.java:106)
07-05 15:36:29.069 29406 29406 E Instrumentation: at android.os.Looper.loop(Looper.java:193)
07-05 15:36:29.069 29406 29406 E Instrumentation: at android.app.ActivityThread.main(ActivityThread.java:6718)
07-05 15:36:29.069 29406 29406 E Instrumentation: at java.lang.reflect.Method.invoke(Native Method)
07-05 15:36:29.069 29406 29406 E Instrumentation: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
07-05 15:36:29.069 29406 29406 E Instrumentation: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
07-05 15:36:29.074 908 5828 I ActivityManager: START u0 {cmp=com.facebook.katana/com.facebook.gdp.LightWeightProxyAuthActivity (has extras)} from uid 10262
07-05 15:36:29.075 665 665 D QCOM PowerHAL: LAUNCH HINT: ON
07-05 15:36:29.121 29406 29406 W ActivityThread: handleWindowVisibility: no activity for token android.os.[email protected]
07-05 15:36:29.125 29406 29406 E Instrumentation: Uninitialized ActivityThread, likely app-created Instrumentation, disabling AppComponentFactory
07-05 15:36:29.125 29406 29406 E Instrumentation: java.lang.Throwable
07-05 15:36:29.125 29406 29406 E Instrumentation: at android.app.Instrumentation.getFactory(Instrumentation.java:1224)
07-05 15:36:29.125 29406 29406 E Instrumentation: at android.app.Instrumentation.newActivity(Instrumentation.java:1215)
07-05 15:36:29.125 29406 29406 E Instrumentation: at X.05O.newActivity(:3382)
07-05 15:36:29.125 29406 29406 E Instrumentation: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2869)
07-05 15:36:29.125 29406 29406 E Instrumentation: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3086)
07-05 15:36:29.125 29406 29406 E Instrumentation: at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
07-05 15:36:29.125 29406 29406 E Instrumentation: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
07-05 15:36:29.125 29406 29406 E Instrumentation: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
07-05 15:36:29.125 29406 29406 E Instrumentation: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
07-05 15:36:29.125 29406 29406 E Instrumentation: at android.os.Handler.dispatchMessage(Handler.java:106)
07-05 15:36:29.125 29406 29406 E Instrumentation: at android.os.Looper.loop(Looper.java:193)
07-05 15:36:29.125 29406 29406 E Instrumentation: at android.app.ActivityThread.main(ActivityThread.java:6718)
07-05 15:36:29.125 29406 29406 E Instrumentation: at java.lang.reflect.Method.invoke(Native Method)
07-05 15:36:29.125 29406 29406 E Instrumentation: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
07-05 15:36:29.125 29406 29406 E Instrumentation: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
07-05 15:36:29.166 4837 4846 W System : A resource failed to call end.
07-05 15:36:29.250 665 665 D QCOM PowerHAL: LAUNCH HINT: OFF
07-05 15:36:29.266 908 952 I ActivityManager: Displayed com.facebook.katana/com.facebook.gdp.LightWeightProxyAuthActivity: +237ms
07-05 15:36:29.266 29463 29463 W BackgroundBroad: type=1400 audit(0.0:9257): avc: denied { read } for name="stats" dev="proc" ino=4026533031 scontext=u:r:untrusted_app:s0:c6,c257,c512,c768 tcontext=u:object_r:proc_qtaguid_stat:s0 tclass=file permissive=0
07-05 15:36:29.447 492 1273 D SurfaceFlinger: duplicate layer name: changing Surface(name=6e58560 com.facebook.katana/com.facebook.gdp.LightWeightProxyAuthActivity)/@0x13e5ed5 - animation-leash to Surface(name=6e58560 com.facebook.katana/com.facebook.gdp.LightWeightProxyAuthActivity)/@0x13e5ed5 - animation-leash#1
07-05 15:36:29.456 492 1273 D SurfaceFlinger: duplicate layer name: changing Surface(name=Dim Layer for - Task=2317)/@0x8471ddb - animation-leash to Surface(name=Dim Layer for - Task=2317)/@0x8471ddb - animation-leash#1
07-05 15:36:29.465 908 2933 I ActivityManager: START u0 {cmp=com.facebook.katana/.gdp.WebViewProxyAuth (has extras)} from uid 10262
07-05 15:36:29.467 665 665 D QCOM PowerHAL: LAUNCH HINT: ON
07-05 15:36:29.469 665 665 D QCOM PowerHAL: Activity launch hint handled
07-05 15:36:29.507 29406 29406 W ActivityThread: handleWindowVisibility: no activity for token android.os.[email protected]
07-05 15:36:29.509 29406 29406 E Instrumentation: Uninitialized ActivityThread, likely app-created Instrumentation, disabling AppComponentFactory
07-05 15:36:29.509 29406 29406 E Instrumentation: java.lang.Throwable
07-05 15:36:29.509 29406 29406 E Instrumentation: at android.app.Instrumentation.getFactory(Instrumentation.java:1224)
07-05 15:36:29.509 29406 29406 E Instrumentation: at android.app.Instrumentation.newActivity(Instrumentation.java:1215)
07-05 15:36:29.509 29406 29406 E Instrumentation: at X.05O.newActivity(:3382)
07-05 15:36:29.509 29406 29406 E Instrumentation: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2869)
07-05 15:36:29.509 29406 29406 E Instrumentation: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3086)
07-05 15:36:29.509 29406 29406 E Instrumentation: at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
07-05 15:36:29.509 29406 29406 E Instrumentation: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
07-05 15:36:29.509 29406 29406 E Instrumentation: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
07-05 15:36:29.509 29406 29406 E Instrumentation: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
07-05 15:36:29.509 29406 29406 E Instrumentation: at android.os.Handler.dispatchMessage(Handler.java:106)
07-05 15:36:29.509 29406 29406 E Instrumentation: at android.os.Looper.loop(Looper.java:193)
07-05 15:36:29.509 29406 29406 E Instrumentation: at android.app.ActivityThread.main(ActivityThread.java:6718)
07-05 15:36:29.509 29406 29406 E Instrumentation: at java.lang.reflect.Method.invoke(Native Method)
07-05 15:36:29.509 29406 29406 E Instrumentation: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
07-05 15:36:29.509 29406 29406 E Instrumentation: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
07-05 15:36:29.517 908 8581 I ActivityManager: START u0 {cmp=com.facebook.katana/.gdp.ProxyAuthDialog (has extras)} from uid 10262
07-05 15:36:29.519 665 665 D QCOM PowerHAL: LAUNCH HINT: ON
07-05 15:36:29.567 29406 29406 W ActivityThread: handleWindowVisibility: no activity for token android.os.[email protected]
07-05 15:36:29.569 29406 29406 E Instrumentation: Uninitialized ActivityThread, likely app-created Instrumentation, disabling AppComponentFactory
07-05 15:36:29.569 29406 29406 E Instrumentation: java.lang.Throwable
07-05 15:36:29.569 29406 29406 E Instrumentation: at android.app.Instrumentation.getFactory(Instrumentation.java:1224)
07-05 15:36:29.569 29406 29406 E Instrumentation: at android.app.Instrumentation.newActivity(Instrumentation.java:1215)
07-05 15:36:29.569 29406 29406 E Instrumentation: at X.05O.newActivity(:3382)
07-05 15:36:29.569 29406 29406 E Instrumentation: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2869)
07-05 15:36:29.569 29406 29406 E Instrumentation: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3086)
07-05 15:36:29.569 29406 29406 E Instrumentation: at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
07-05 15:36:29.569 29406 29406 E Instrumentation: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
07-05 15:36:29.569 29406 29406 E Instrumentation: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
07-05 15:36:29.569 29406 29406 E Instrumentation: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
07-05 15:36:29.569 29406 29406 E Instrumentation: at android.os.Handler.dispatchMessage(Handler.java:106)
07-05 15:36:29.569 29406 29406 E Instrumentation: at android.os.Looper.loop(Looper.java:193)
07-05 15:36:29.569 29406 29406 E Instrumentation: at android.app.ActivityThread.main(ActivityThread.java:6718)
07-05 15:36:29.569 29406 29406 E Instrumentation: at java.lang.reflect.Method.invoke(Native Method)
07-05 15:36:29.569 29406 29406 E Instrumentation: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
07-05 15:36:29.569 29406 29406 E Instrumentation: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
07-05 15:36:29.651 492 540 D SurfaceFlinger: duplicate layer name: changing com.facebook.katana/com.facebook.katana.gdp.ProxyAuthDialog to com.facebook.katana/com.facebook.katana.gdp.ProxyAuthDialog#1
07-05 15:36:29.697 492 1763 D SurfaceFlinger: duplicate layer name: changing Dim Layer for - Task=2317 to Dim Layer for - Task=2317#1
07-05 15:36:29.720 665 665 D QCOM PowerHAL: LAUNCH HINT: OFF
07-05 15:36:29.731 492 540 W SurfaceFlinger: Attempting to set client state on removed layer: Dim Layer for - Task=2317#0
07-05 15:36:29.731 492 540 W SurfaceFlinger: Attempting to destroy on removed layer: Dim Layer for - Task=2317#0
我注意到使用了
NATIVE_WITH_FALLBACK
模式并更改为
WEB_ONLY
进行测试。
虽然这让我超越了上面描述的原始问题,但却创造了另一个问题。
它不是向我询问登录详细信息,而是显示以下内容:
同样,文本是:
您之前使用Facebook登录了$ MY_APP。 你想继续吗?
如果我选择继续(除了取消之外别无选择),它会返回到我的应用程序,但Firebase会向我提供
ERROR_ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL
错误,表明该帐户已与其他提供商关联。
当我签入Firebase控制台时,该帐户显示为Facebook帐户。
因此,就像安装Facebook应用程序一样,Firebase认为它是一个独立的社交提供商或其他东西。
最后,有点出于绝望,我尝试将身份验证模式切换到
WEB_VIEW_ONLY
。
果然,这显示了与没有安装Facebook时登录时完全相同的体验。
此外,一切都按预期工作。
我的问题是,我不完全确定这一切的含义是什么(注意:请参阅下面的更新)。 我记得在某个地方读过关于本地Facebook登录的东西不再是真正的东西(或者它可能是相反的,它 应该 被使用)。 基本上,我很困惑,非常感谢以下问题的任何答案:
-
使用
WEB_VIEW_ONLY
是可以接受的吗? -
为什么使用
NATIVE_WITH_FALLBACK
在帖子NATIVE_WITH_FALLBACK
显示错误? -
为什么
WEB_ONLY
似乎将同一帐户视为不同的提供商? - 为什么Facebook登录SDK在这些模式下的表现如此不同? 我认为它们是一种无害的 偏好 ,对身份验证本身没有任何影响,但天哪我错了。
请注意,在所有情况下,我都遵循 官方文档 ,包括使用最新的SDK版本:
implementation 'com.facebook.android:facebook-login:[5,6)'
谢谢你的帮助。
更新:
我将我的应用程序更新为
WEB_VIEW_ONLY
并重新提交。
Facebook现在告诉我:
您的应用程序现在违反了平台策略8.2:实现Facebook登录的原生iOS和Android应用程序必须使用我们的官方SDK进行登录。 请确保您的应用使用最新版本的SDK for Login。
所以我现在卡在一块岩石和一块坚硬的地方之间。
您的日志说密钥哈希不匹配,所以你需要在Facebook开发者帐户添加密钥哈希我正在共享代码的和平功能你只需要调用此功能并打印日志,显示你的密钥,只需更新你的fb开发者帐户中的密钥哈希..
public void generatekeyhash() {
try {
PackageInfo info = getPackageManager().getPackageInfo(
getPackageName(),
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 (PackageManager.NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
}
这是对这个问题的解释:
07-05 15:36:28.946 29406 4941 W fb4a.BlueServiceQueue:服务期间的异常07-05 15:36:28.946 29406 4941 W fb4a.BlueServiceQueue:X.2LH:[code] 404 [message]:密钥哈希GtvUdcOKFRAE0RY0LIw5veCA + M8 =与任何存储的键哈希值不匹配。 (404)[extra]:null
请记住,您在Facebook应用程序中配置的Key Hash与您的应用程序签名的Keystore(证书)相关。
你必须使用你签署你的应用程序的密钥哈希,如果你不知道它,我建议你从你的密钥库再次获取它:
https://developers.facebook.com/docs/android/getting-started/
为什么Facebook登录SDK在这些模式下的表现如此不同? 我认为它们是一种无害的偏好,对身份验证本身没有任何影响,但天哪我错了。
在网络中你没有问题但是如果你在应用程序中需要授权使用应用程序,并且 对于Android应用程序中的这个实现 非常重要 ,你需要使用Facebook SDK ,在这种情况下你需要获取用于签署应用程序的密钥哈希证书。
这里的许多答案都提供了部分解决方案,但我相信这是完整的解决方案和解释。
您面临的问题与HashKey值不匹配,这些值与 您构建apk 的 设备 不匹配。 您使用的计算机,运行构建apk的mac,pc等具有不同的哈希键,并且该哈希键被融合到最终的apk构建中,因此如果构建是从不同的计算机完成的,则Facebook登录将不起作用。
解决方案是做两件事。
首先,每当你在新计算机上创建一个apk构建时,你需要生成HashKey字符串并抓住它。 执行此操作的代码如下:
public static String getMyHashKey(Context context, String packageName){
try {
PackageInfo info = context.getPackageManager().getPackageInfo(
packageName, PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance(SHA);
md.update(signature.toByteArray());
return Base64.encodeToString(md.digest(), Base64.DEFAULT);
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return null;
}
其次,您需要在设置中将该字符串添加到您的Facebook应用程序。 这可以通过以下两个步骤来完成:
1)转到 developers.facebook.com 并转到相关应用程序。 然后单击设置 - >基本。
2)之后,向下滚动到Android区域并填写字段。 请注意,您可以拥有多个HashKeys!
3)保存更新,等待几分钟以进行更新,然后重试。 这应该可以解决您面临的问题。