android - 為什麼Facebook身份驗證SDK的行為方式如此不同,具體取決於其模式?




firebase firebase-authentication (4)

我在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。

所以我現在卡在一塊岩石和一塊堅硬的地方之間。


它說,在日誌的頂部
Key hash GtvUdcOKFRAE0RY0LIw5veCA+M8= does not match any stored key hashes.

在構建發佈時,您可能使用了錯誤的keyhash。 顯然,當您使用 此鏈接中 討論的錯誤keyhash時會發生此問題。

至於為什麼它在WEB模式下工作,因為keyhash由SDK檢查,因為你轉到網頁,你不會得到錯誤。 您正在調試模式和調試模式下運行密鑰哈希可能是正確的,這可能是它在您的設備上工作的答案。


您的日誌說密鑰哈希不匹配,所以你需要在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)保存更新,等待幾分鐘以進行更新,然後重試。 這應該可以解決您面臨的問題。







facebook-authentication