首页 > 解决方案 > React Native Facebook SDK ShareDialog 要求再次登录

问题描述

我目前正在使用 react native 做一个项目,我需要让用户使用 facebook 登录。所以我使用React-native-fbsdk LoginButton组件让用户登录并获取访问令牌。项目的一部分还需要让用户共享指向其个人资料的链接。

为了做到这一点,我关注了 Facebook 的GitHub存储库,其中说明了如何添加 ShareDialog。添加两个LoginButton和后ShareDialog,我运行了该应用程序。登录成功,我得到了访问令牌。但是当我尝试分享链接时,它要求我重新登录。如果我使用 ShareDialog 登录,它可以让我按预期分享帖子和所有内容。

但是,如果我LoginButton也使用 ShareDialog 登录后注销,则两个组件都会成功执行注销。问题是登录不处理单个登录的两个组件。

下面是我的代码。

render() {
return (
  <View style={styles.container}>
    <LoginButton
      publishPermissions={["publish_actions"]}
      onLoginFinished={
        (error, result) => {
          if (error) {
            alert("Login failed with error: " + error.message);
          } else if (result.isCancelled) {
            alert("Login was cancelled");
          } else {
            alert("Login was successful with permissions: " + result.grantedPermissions)
          }
        }
      }
      onLogoutFinished={() => alert("User logged out")}/>
    <TouchableHighlight onPress={this.shareLinkWithShareDialog}>
      <Text style={styles.shareText}>Share link with ShareDialog</Text>
    </TouchableHighlight>
  </View>
 );
}

shareLinkWithShareDialog = () => {

const shareLinkContent = {
  contentType: 'link',
  contentUrl: 'https://www.sample.com/',
  contentDescription: 'Test Sharing Description'
};
 var tmp = this;
 ShareDialog.canShow(shareLinkContent).then(
 (canShow) => {
    if (canShow) {
      return ShareDialog.show(shareLinkContent);
    }
  }
).then(
 (result) => {
    if (result.isCancelled) {
      alert('Share cancelled');
    } else {
      alert('Share success with postId: ' + result.postId);
    }
  },
 (error) => {
    alert('Share fail with error: ' + error);
  }
 );
}

请在这里帮助我。我无法确定这有什么问题。

笔记

我使用 Facebook 的测试用户对此进行了检查,它还拥有所有相关权限manage_pages,包括测试用户也拥有自己的测试页面

标签: facebookreact-nativefbsdkreact-native-fbsdk

解决方案


我遇到了类似的问题,那是因为我没有在手机上安装 facebook 应用程序。看起来你的代码很好。

但是我没有在 facebook 中使用测试页面和测试用户选项,但我希望它们在功能方面与普通用户没有什么不同。只需尝试安装 facebook 应用程序并运行您的应用程序。应该没事。


推荐阅读