FB.Event.subscribe + comments.add不起作用?

时间:2010-06-17 08:36:16

标签: facebook

我正在尝试在发送评论时捕获事件。我究竟做错了什么?我只是想将每个用户评论也更新到facebook组墙,这就是我需要抓住这个事件的原因。

<fb:comments numposts="10" ></fb:comments>   

FB.init和事件捕手:

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId  : 'sensored-app-id',
      status : true, // check login status
      cookie : true, // enable cookies to allow the server to access the session
      xfbml  : true  // parse XFBML
    });

    /* All the events registered */
    FB.Event.subscribe('comments.add', function (response) {
        // do something with response
        alert("comment added");
    });



  };

  (function() {
    var e = document.createElement('script');
    e.src = document.location.protocol + '//connect.facebook.net/fi_FI/all.js';
    e.async = true;
    document.getElementById('fb-root').appendChild(e);
  }());
</script>   

6 个答案:

答案 0 :(得分:5)

您需要将notify="true"属性添加到fb:comments标记。添加属性后,comments.add事件就会开始起作用。

<fb:comments numposts="10" notify="true"></fb:comments>

或者,如果您使用的是较新的html5兼容标签:

<div class="fb-comments" data-num-posts="10" data-notify="true" ></div>

答案 1 :(得分:5)

FB.Event.subscribe('comment.create', function(response) {
    console.log(response);
});

答案 2 :(得分:3)

FB.Event.subscribe('comment.create', function(response) {

          FB.api({
            method: 'fql.query',
            query: "SELECT post_fbid, fromid, object_id, text, time from comment WHERE  object_id in (select comments_fbid from link_stat where url ='${session.url}') order by time desc limit 1"
          },
          function(response) {
            var feed = response[0];          
            alert(feed.text)
          }
        );
      });  

答案 3 :(得分:1)

您需要确保添加notify="true"标记,如果这不适合您,请确保您使用的是最新的fbComments插件。尝试添加migrated="1"标记,如下所示,看看是否有帮助:

<fb:comments notify="true" migrated="1"></fb:comments>

答案 4 :(得分:1)

您应该注意,您必须在调用FB.init后订阅事件。现在适合我。但是,XML Render最近有一个bug

答案 5 :(得分:0)

奇怪的是,如果我在我的comment.create函数(响应)中只有一个变量赋值和一个ajax帖子,则事件不会触发,但是如果我在底部添加一个JS警告语句或者在dud return语句中它可以工作??例如:

FB.Event.subscribe("comment.create", function(response) {
  var postData = "page_title='.$safe_page_title.'";

  $.ajax({
    type: "POST",
    url: "/post/post_facebook_comment.php",
    data: postData
  });

  return true;
});