我正在尝试使用Facebook SDK 4.41.0在Android上实现Facebook分享 但是,我面临以下问题:当共享对话框出现时,它将立即关闭,并且OnError回调方法将引发以下错误
CONNECTION_FAILURE: CONNECTION_FAILURE
at com.facebook.internal.NativeProtocol.getExceptionFromErrorData(NativeProtocol.java:811)
at com.facebook.share.internal.ShareInternalUtility.handleActivityResult(ShareInternalUtility.java:169)
at com.facebook.share.internal.ShareInternalUtility$3.onActivityResult(ShareInternalUtility.java:261)
at com.facebook.internal.CallbackManagerImpl.onActivityResult(CallbackManagerImpl.java:91)
at android.support.v4.app.FragmentActivity.onActivityResult(FragmentActivity.java:160)
有什么想法会失败吗?
这是一些相关的代码段:
facebookCallbackManager = CallbackManager.Factory.create()
if (ShareDialog.canShow(ShareLinkContent::class.java)) {
val url = "https://www.example.com"
url?.let {
val shareUri = it.toUri()
val content = ShareLinkContent.Builder().setContentUrl(shareUri).build()
val dialog = ShareDialog(this)
dialog.registerCallback(facebookCallbackManager, object : FacebookCallback<Sharer.Result> {
override fun onSuccess(result: Sharer.Result?) {
Timber.i("Success on Facebook share")
}
override fun onCancel() {
Timber.i("Facebook cancelled")
}
override fun onError(error: FacebookException?) {
Timber.e(error, "facebook share failed")
}
})
dialog.show(content)