facebook - 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
,包括测试用户也拥有自己的测试页面。
解决方案
我遇到了类似的问题,那是因为我没有在手机上安装 facebook 应用程序。看起来你的代码很好。
但是我没有在 facebook 中使用测试页面和测试用户选项,但我希望它们在功能方面与普通用户没有什么不同。只需尝试安装 facebook 应用程序并运行您的应用程序。应该没事。
推荐阅读
- python - 尝试在递归中处理更大的数字时冻结
- c++ - 目标名称“lib/process.bin”被保留或对某些无效
- python - 将包含字典的数据框单元格转换为具有新列 pandas 的数据框
- java - 我正在为大学课程使用 SceneBuilder/FXML 编写带有 GUI 的 Java 程序(抵押计算器),但我遇到了错误
- javascript - 如何使文本在具有 2 个变量的按钮脚本上水平滚动?
- json - 使用 ijson.parse() 和 ijson.items() 加载一个大的 JSON 文件 - 为什么这样会起作用?
- reactjs - ReactJs 中的路由器
- python - ModuleNotFoundError:将我的 Django 应用程序迁移到 Heroku 时没有名为“Django-Banking-App.settings”的模块
- sql - 可选择加入多对多表
- c++ - C++中的BST,添加节点时返回true或false