FB Comments Plugin - Detect comment on page

2019-09-03 06:28发布

How can I detect when a comment is made on my page with the Comments Plugin? I'm currently using the Facebook PHP SDK, reading the Facebook documentation it says I need the JS SDK, but it's not really clear on how you accomplish what I want to do.

1条回答
趁早两清
2楼-- · 2019-09-03 06:55

I guess it's straight forward:

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'YOUR_APP_ID', // App ID
      channelURL : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
      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
    });

    FB.Event.subscribe('comment.create',
        function(response) {
            alert('A new comment has been added!');
        }
    );

  };

  // 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>

Documents: 1 - 2

查看更多
登录 后发表回答