2010-06-17 15 views
8

Tôi đang cố gắng nắm bắt sự kiện khi nhận xét được gửi. Tôi đang làm gì sai? Tôi chỉ muốn cập nhật mọi nhận xét của người dùng cũng vào tường nhóm facebook và đó là lý do tại sao tôi cần phải nắm bắt sự kiện.FB.Event.subscribe + comments.add không hoạt động?

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

FB.init và sự kiện catcher:

<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> 
+0

tôi sẽ đặt mã này ở đâu nếu tôi có trang web drupal? – LTech

Trả lời

5

Bạn cần phải thêm notify="true" thuộc tính cho thẻ fb:comments. Khi bạn thêm thuộc tính, sự kiện comments.add sẽ bắt đầu hoạt động.

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

hoặc, nếu bạn đang sử dụng html5 mới hơn thẻ phù hợp:

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

cái gì? Làm thế nào bạn tìm thấy điều này? nó không được ghi lại. – typeoneerror

+0

Việc thêm tham số 'notify =" true "' không khắc phục được sự cố cho tôi. Bất kỳ ai khác vẫn gặp sự cố/biết giải pháp? –

5
FB.Event.subscribe('comment.create', function(response) { 
    console.log(response); 
}); 
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) 
      } 
     ); 
     }); 
1

Bạn cần phải chắc chắn thêm thẻ notify="true", và nếu điều đó không làm việc cho bạn, hãy chắc chắn bạn đang sử dụng plugin fbComments mới nhất. Thử thêm thẻ migrated="1" như dưới đây, và xem nếu điều này giúp:

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

Di chuyển = "1" là điều duy nhất làm việc cho tôi vì một lý do nào đó. –

1

bạn nên lưu ý rằng bạn cần phải đăng ký cho các sự kiện sau gọi FB.init. Làm việc cho tôi ngay bây giờ. Tuy nhiên, XML Render đang gặp lỗi gần đây

0

Thật lạ, nếu tôi chỉ có một bài tập biến và một bài đăng ajax trong hàm comment.create (phản hồi) sự kiện không kích hoạt, nhưng nếu tôi thêm câu lệnh cảnh báo JS ở phía dưới hoặc một tuyên bố trở lại dud nó hoạt động ?? Ví dụ:

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; 
});