如何将我的网站内容分享到Facebook?
我已经尝试过 Sharer 和对话,但这些不会显示图片。
我的代码:
function facebook_share(){
FB.init({
appId : '1884730308422253',
status : true,
xfbml : true,
version : 'v2.8'
});
FB.ui({
method: 'feed',
name: 'Come Listen to this Song',
link: 'http://192.168.0.100/catchthemyoung/student',
picture: 'http://192.168.0.100/catchthem/images/timeline/EPUQuotgRj.png',
caption: 'mywebsite.com',
description: 'msg',
message: 'msg'
},
// callback
function(response) {
if (response && !response.error_message) {
alert('Posting completed.');
} else {
alert('Error while posting.');
}
}
);
}
答案 0 :(得分:0)
请确保您的域名已注册您的应用ID“1884730308422253” 请首先使用网站添加平台添加app域名=>选择网站并添加链接 https://developers.facebook.com/apps/XXXXXXXXXXXXX[Yourid]/settings/
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function () {
FB.init({
appId: '889551921179700',
xfbml: true,
version: 'v2.8'
});
};
(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement(s);
js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<span id="share_button" class="fb-btn">
<div class="fb_icon"></div>
<span class="fb-share">
<i class="fa fa-facebook"></i> Share
</span>
</span>
<script type="text/javascript">
document.getElementById('share_button').onclick = function () {
FB.ui({
method: 'share',
display: 'popup',
caption: 'Your Title',
picture: 'Your picture',
description: 'Your description',
href: 'Your link',
}, function (response) {
});
}
</script>