我目前正在使用React native做一个项目,我需要让用户使用Facebook登录。因此,我使用React-native-fbsdk LoginButton
组件让用户登录并获取访问令牌。另外,项目需求的一部分还允许用户共享指向其个人资料的链接。
为了做到这一点,我跟随Facebook的GitHub repo,说了如何添加ShareDialog。在添加LoginButton
和ShareDialog
之后,我运行了该应用程序。登录成功,我获得了访问令牌。但是,当我尝试共享链接时,它要求我再次登录。如果我使用ShareDialog登录,它可以让我按预期共享帖子和所有内容。
但是,如果我也使用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);
}
);
}
请在这里帮助我。我无法确定这是怎么回事。
注意
我使用Facebook Test User进行了检查,它还具有所有相关权限,包括manage_pages
,并且测试用户也拥有自己的Test Page。
答案 0 :(得分:1)
我遇到了类似的问题,那是因为我没有在手机上安装facebook应用程序。似乎您的代码很好。
但是我没有在facebook中使用“测试页”和“测试用户”选项,但是我希望它们在功能方面与普通用户没有什么不同。只需尝试安装facebook应用程序并运行您的应用程序即可。应该没事。