[英]Facebook javascript firing on a “share”
首先,您需要在页面中加载Javascript SDK
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'YOUR_APP_ID', // App ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
oauth : true, // enable OAuth 2.0
xfbml : true // parse XFBML
});
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
接下来,您有一个包含用于打开共享对话框的FB.ui代码的函数。 在FB.ui函数中,您可以看到回调开始function(response) {
,其中'响应'包含一些可帮助您确定用户是否共享消息的详细信息。
在回调中,我们做一个IF语句。 如果用户确实发布了消息response.post_id,并且包含成功发布的消息的ID,那么我们可以做任何我们想做的事情,在这个例子中弹出一个警告,说“帖子已发布”
function share(){
FB.ui(
{
method: 'feed',
name: 'Facebook Dialogs',
link: 'http://developers.facebook.com/docs/reference/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
caption: 'Reference Documentation',
description: 'Dialogs provide a simple, consistent interface for applications to interface with users.',
message: 'Facebook Dialogs are easy!'
},
function(response) {
if (response && response.post_id) {
// THE POST WAS PUBLISHED
alert('Post was published.');
} else {
// THE POST WAS NOT PUBLISHED
alert('Post was not published.');
}
}
);
}
在这里,您有如何初始化FB Javascript SDK的说明,然后使用您链接中的函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.