我使用 react-native 来分享我在 mycode 中写的
const FBSDK = require('react-native-fbsdk');
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
TouchableHighlight,
View,
} from 'react-native';
const {
LoginButton,
ShareDialog,
} = FBSDK;
class HelloFacebook extends Component {
constructor(props) {
super(props);
const shareLinkContent = {
contentType: 'link',
contentUrl: 'https://www.facebook.com',
contentDescription: 'Wow, check out this great site!',
};
this.state = {
shareLinkContent: shareLinkContent,
};
}
shareLinkWithShareDialog() {
var tmp = this;
ShareDialog.canShow(this.state.shareLinkContent).then(
function(canShow) {
if (canShow) {
return ShareDialog.show(tmp.state.shareLinkContent);
}
}
).then(
function(result) {
if (result.isCancelled) {
alert('Share cancelled');
} else {
alert('Share success with postId: '
+ result.postId);
}
},
function(error) {
alert('Share fail with error: ' + error);
}
);
}
render() {
alert("render")
return (
<View style={styles.container}>
<LoginButton />
<TouchableHighlight style={styles.share}
onPress={this.shareLinkWithShareDialog.bind(this)}>
<Text style={styles.shareText}>Share link with ShareDialog</Text>
</TouchableHighlight>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
shareText: {
fontSize: 20,
margin: 10,
},
});
AppRegistry.registerComponent('HelloFacebook', () => HelloFacebook);
但是这里的输出我只得到了我想分享的链接,我没有得到任何我想分享的描述 我需要的是: 我想分享 contentDescription 和 contentUrl,所以请任何人给我建议我的代码有什么问题吗,非常感谢任何帮助