Jon*_*ont 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>
Run Code Online (Sandbox Code Playgroud)

接下来,您有一个包含用于打开共享对话框的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.');

      }
    }
  );
}
Run Code Online (Sandbox Code Playgroud)