React Native Facebook SDK ShareDialog 要求再次登录

React Native Facebook SDK ShareDialog asks to login again

我目前正在做一个使用本机反应的项目,我需要让用户使用 facebook 登录。所以我使用 React-native-fbsdk LoginButton 组件让用户登录并获取访问令牌。该项目的一部分还需要让用户分享 links 到他们的个人资料。

为了做到这一点,我关注了 Facebook 的 GitHub repo,其中说明了如何添加 ShareDialog。添加 LoginButtonShareDialog 后,我 运行 应用程序。登录成功,我得到了访问令牌。但是当我尝试共享 link 时,它要求我重新登录。如果我使用 ShareDialog 登录,它可以让我按预期共享 post 和所有内容。

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

下面是我的代码。

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);
  }
 );
}

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

备注

我也用 Test User of Facebook and it also has all relevant permissions including manage_pages and test user has it's own Test Page 检查了这个。

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

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