gpt4 book ai didi

Android Facebook登录失败无异常,只是 "Sorry something went wrong"

转载 作者:行者123 更新时间:2023-12-02 16:26:08 28 4
gpt4 key购买 nike

我正在尝试在我的应用程序中实现 Facebook 登录,但我遇到了一个非常特殊的问题,登录过程开始时失败,并显示一条非常神秘的消息,并且我的应用程序端没有抛出异常,所以我不'不知道发生了什么。

我怀疑我在登录过程中使用 DialogFragment 与我有关,而 Facebook LoginButton 是此 DialogFragment 的一部分code> 而不是普通的 fragment 或 Activity 。我在 XML 中添加登录按钮:

 <com.facebook.login.widget.LoginButton
android:id="@+id/loginFacebookButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/default_margin_double"
android:layout_marginEnd="@dimen/default_margin_double"
android:layout_marginBottom="@dimen/default_margin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:background="@drawable/rounded_blue_bg"
android:layout_marginTop="@dimen/default_margin"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="@dimen/default_margin_double"
app:layout_constraintBottom_toTopOf="@id/loginOrLayout" />

我在代码中添加了回调,在我的 onCreateDialog

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = super.onCreateDialog(savedInstanceState)
setStyle(STYLE_NORMAL, R.style.FullscreenDialog)

val view = View.inflate(context, R.layout.fragment_login, null)

//FB Login callback manager
val callbackManager = CallbackManager.Factory.create()
val fbLoginButton = view.loginFacebookButton
fbLoginButton.fragment = this
fbLoginButton.setPermissions(listOf("name", "email", "public_profile"))
fbLoginButton.loginBehavior = LoginBehavior.NATIVE_WITH_FALLBACK
fbLoginButton.registerCallback(callbackManager,
object : FacebookCallback<LoginResult> {
override fun onSuccess(loginResult: LoginResult) {
fbLoginSuccessful(loginResult)
}

override fun onCancel() {}

override fun onError(exception: FacebookException) {
Log.w(TAG, "onError: Failed to login with FB.", exception)
loginFailed(exception.localizedMessage)
}
})

return dialog
}

当我按下登录按钮时,我会看到一个正在加载的进度栏,然后 Facebook 应用程序打开,我点击我的帐户,然后在进行更多加载后,我会看到以下屏幕:

Facebook Login Error

我已遵循文档 here但我似乎无法让它发挥作用。任何帮助是极大的赞赏。我什至从我的代码中打印了 key 哈希,如前所述 here in the documnetation ,并且我在开发人员控制台上有正确的哈希值,但仍然出现错误。谢谢

最佳答案

我的 fragment 中似乎缺少以下内容:

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
callbackManager.onActivityResult(requestCode, resultCode, data)
super.onActivityResult(requestCode, resultCode, data)
}

但是,它可能没有相关性,因为错误是在实际 FB Activity 返回之前抛出的,所以可能是一个已修复的 Facebook 内部错误。

祝遇到类似问题的人好运,对 FB SDK 的支持实际上不存在。

关于Android Facebook登录失败无异常,只是 "Sorry something went wrong",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58929622/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com