如何使用React native在Facebook上分享/发布内容



我正试图在我的react原生应用程序中在Facebook上发帖/分享。但我做不到。这是我使用react原生fbsdk lib在我的facebook订阅源上发布的代码:

shareLinkWithDialog = async () => {
const canShow = await ShareDialog.canShow(SHARE_LINK_CONTENT);
if (canShow) {
try {
const {isCancelled, postId} = await ShareDialog.show(
SHARE_LINK_CONTENT,
);
if (isCancelled) {
Alert.alert('Share cancelled');
} else {
Alert.alert('Share success with postId: ' + postId);
}
} catch (error) {
Alert.alert('Share fail with error: ' + error);
}
}
};

现在,我该怎么分享呢?

<View>
<LoginButton
onLoginFinished={
(error, result) => {
if (error) {
console.log("login has error: " + result.error);
} else if (result.isCancelled) {
console.log("login is cancelled.");
} else {
setLoggedIn(true);
AccessToken.getCurrentAccessToken().then(
(data) => {
console.log(data.accessToken.toString());
this.getPublicProfile();
}
)
}
}
}
onLogoutFinished={() => {
console.log("logout.");
setLoggedIn(false);
}}/>
{ isLoggedIn && <Card
title={profile.name}>
<Image
source={{ uri: profileImage }}
style={{ width: 50, height: 50 }}
/>
<TouchableHighlight onPress={this.shareLinkWithDialog}>
<Text style={styles.shareText}>Share link with ShareDialog</Text>
</TouchableHighlight>
</Card> 
}
</View>

提前谢谢。

您可以使用react native提供的共享对话。它将打开操作系统的默认共享对话框。它将有各种安装的应用程序,如消息,电子邮件,脸书,Whatsapp等…


import { Share } from 'react-native';
Share.share({
message: message + ' ' + url,
url: url,
title: STRING.INVITATION_TO_FOMOYOLO
}).then(({ action, activityType }) => {
cb(action, activityType)
}).catch((e) => console.warn('error', e));

最新更新