2010-07-28 96 views
0

我在我的網站上使用<fb:comments>,但我不知道如何從具有特定XID的評論框中檢索評論數。檢索在Facebook評論框中的評論數

我試圖攔截用下面的代碼的所有新評論:

FB.Event.subscribe('comments.add', function(response) { alert("Comment was added."); });

我從未想過收到警報。有任何想法嗎?我只需要任何給定框的評論數量。

回答

0

你在問兩個不同的問題。 1)如何獲得評論數量,以及2)如何使用JavaScript跟蹤評論事件。對於2,您需要註釋標記才能包含notify =「true」以便觸發事件。

<fb:comments xid="comment_xxx" notify="true"></fb:comments> 
+3

在世界的哪個地方,你看到提及'notify ='true''屬性?甚至沒有在他們的文檔中提到! – TMC 2011-04-28 03:46:01

1

您應該能夠從link_stat表中通過FQL獲得comment_count字段,通過爲您的評論插件提供url頁面。

如果這不起作用,您還可以從comment表中獲得xid的所有評論,然後自己對其進行計數(FQL不支持COUNT)。但返回的記錄數量有限制,因此很可能只返回前5000條評論。

+0

我還需要在添加新的評論,所以我可以通知網站所有者檢測。 – 2010-07-29 04:28:14

4

你可以得到你的意見計數這個簡單的FB標籤:

<fb:comments-count href="${url_of_your_page}"></fb:comments-count> Comment 
0

此代碼爲我工作

<script> 
    // fb init 
    window.fbAsyncInit = function() { 
     FB.init({ 
      appId: 'you app id', 
      status: true, 
      cookie: true, 
      xfbml: true 
     }); 

     // this event is fired where a comment is created 

     FB.Event.subscribe('comment.create', function(response) { 
      alert(response.commentID); 
     });   

    }; 

    // im using jquery to make ajax request 
    $(function(){ 

    $.ajax({ 
     url: "http://graph.facebook.com/?ids=[SITE URL]", 
     dataType: 'json', 
     success: function(data){ 
     var items = []; 
     $.each(data, function(key, val) { 
      items.push(val) 
      }); 
      alert(items[0].comments); 
      console.log(items); 
      } 
    }); 

items [0] .comments是你在找什麼

走在控制檯中,您可以看到的項目是這樣的:

[Object { 
id="site url", 
shares=65, 
comments=87 
}]