我希望实现一个功能,一旦用户给任何项目评级,Facebook共享窗口应该默认打开。
通常,我使用以下社交分享代码:
但是我不希望用户按下共享按钮来调用对话框。
是否有一种方法来自动调用这个FB共享框使用上述脚本通过传递一些参数?
。http://kindheartz.com/gallery/image/1-weds-trust-madurai fwgallerytop
在图库中,当用户对图片进行评分时,我希望FB分享框默认弹出
您需要将facebook Javascript SDK加载到您的页面
Facebook SDK for JavaScript没有任何独立的文件需要下载或安装,而只需要包含在HTML中加入一小段普通的JavaScript异步地将SDK加载到页面中。异步加载意味着它不会阻止加载页面上的其他元素
要加载facebook javascript SDK,请将此代码放在您的<body>
标签后面:
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '{your-app-id}',
status : true,
xfbml : true
});
};
(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/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
记住用你的APP ID替换{your-app-id}
,如果你没有任何应用可以在这里创建:https://developers.facebook.com/apps
当你完成并检查Javascript SDK是否被正确加载时,只需将这段代码添加到页面底部:
<script>
$(document).on("click", "#YOUR_RATING_BUTTON", function(){
var id= $(this).data('id');
var photo= $(this).data('photo');
var obj = {
method: 'feed',
link: '{The link you want to share}',
picture: '{the url of the photo you want}',
name: '{The name of the link attachment}',
description: '{The description of the link (appears beneath the link caption). If not specified, this field is automatically populated by information scraped from the link, typically the title of the page}',
display: 'popup'
};
function callback(response) {
//do something with callback
if (response && response.post_id) {
alert('Thank you for sharing this rating.');
} else {
alert('Rating was not shared.');
}
}
FB.ui(obj, callback);
});
</script>
你可以在这里阅读更多关于Javascript SDK的内容你可以在这里和这里阅读更多关于Facebook Feed Dialog的内容