从 Facebook 评论框中检索评论计数

发布于 2024-09-11 12:54:11 字数 240 浏览 3 评论 0原文

我在网站上使用 ,但我不知道如何从具有特定 XID 的评论框中检索评论计数。

我尝试使用以下代码拦截所有新评论:

FB.Event.subscribe('comments.add', function(response) { alert("评论已添加。"); });

但我从未收到过警报。有什么想法吗?我只需要任何给定框的评论数量。

I use <fb:comments> on my website, but I can't figure out how to retrieve the comment count from a comment box with a specific XID.

I've tried intercepting all new comments with the following code:

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

I never receive the alert though. Any ideas? I just need the number of comments for any given box.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

不打扰别人 2024-09-18 12:54:11

您可以使用这个简单的 Facebook 标签来获取评论数:

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

You can get the count of your comments with this simple fb tag:

<fb:comments-count href="${url_of_your_page}"></fb:comments-count> Comment
别闹i 2024-09-18 12:54:11

您应该能够从 link_stat 获取 comment_count 字段通过 FQL 提供带有评论插件的页面的 url 表。

如果这不起作用,您还可以从 comment 表中获取 xid 的所有评论,然后自己计算它们(FQL 不支持 COUNT )。但返回的记录数量有限制,因此很可能只会返回前 5,000 条评论。

You should be able to get comment_count field from link_stat table through FQL by providing url of a page with your comment plugin.

If that doesn't work you can also get all comments by xid from comment table and then count them yourself (FQL doesn't support COUNT). But there is a limit on returned number of records, so most likely it would return only first 5,000 comments.

看透却不说透 2024-09-18 12:54:11

我找了好久的答案,终于找到了。

保存后即可阅读评论。

你可以看到:
Guardar 评论 facebook

I was finding the answer a lot of time, and finally i found it.

You can read comments when it is saved.

You can see:
Guardar comentarios facebook

漫雪独思 2024-09-18 12:54:11

您在问两个不同的问题。 1) 如何获取评论计数,2) 如何使用 JavaScript 跟踪评论事件。对于 2,您需要注释标记包含 notification="true" 才能触发事件。

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

You are asking two separate questions. 1) how to get a count of comments, and 2) how to track the comment event with JavaScript. For 2, you need the comment tag to include notify="true" in order for the event to be fired.

<fb:comments xid="comment_xxx" notify="true"></fb:comments>
霊感 2024-09-18 12:54:11

此代码对我有用

<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
}]  

this code is working for me

<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 is what you are looking for

take a look in the console you can see that items is like this :

[Object {
id="site url",  
shares=65,  
comments=87
}]  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文