2011-10-30 33 views

回答

7

首先你需要擁有的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.'); 

     } 
    } 
); 
} 
1

Here你有指示如何初始化FB Javascript SDK,然後使用你的鏈接中的函數。