[英]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.