Html 如何使用 HTML5 获得 Facebook 评论数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7642631/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 10:55:55  来源:igfitidea点击:

How to get Facebook comments count with HTML5?

facebookhtml

提问by Caio Tarifa

I know two ways to retrieve the number of comments on Facebook:

我知道两种方法来检索 Facebook 上的评论数量:

<fb:comments-count href=http://example.com/></fb:comments-count> awesome comments 

and...

和...

<iframe src="http://www.facebook.com/plugins/comments.php?href=example.com&permalink=1" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:130px; height:16px;" allowTransparency="true"></iframe> 

But none is a semantics for HTML5 solution, is there any alternative?

但是没有一个是 HTML5 解决方案的语义,还有其他选择吗?

采纳答案by Caio Tarifa

Since v2.3, it can be handled by span, which already has the natively display: inline;semantics.

v2.3 开始,它可以由span已经具有本机display: inline;语义的 处理。

<a href="/post-link">
  <span class="fb-comments-count" data-href="/post-link">0</span> comments
</a>

回答by Charlie Nibbana

You can also get HTML5 valid FB comment count this way:

您还可以通过这种方式获得 HTML5 有效的 FB 评论数:

<div class="fb-comments-count" data-href="/post URL">0</div>

FB automatically replaces the "0" with the correct number. If you put something there like "awesome comments", it will be replaced with the number of comments i.e. "13", etc.

FB 自动用正确的数字替换“0”。如果您在那里放置诸如“很棒的评论”之类的内容,它将被替换为评论数量,即“13”等。

In order to get the number and use your own text, do something like this:

为了获取数字并使用您自己的文本,请执行以下操作:

<a href="/post URL"><div class="fb-comments-count" data-href="/post URL">0</div> awesome comments</a>

Notice you must wrap your class in div's or else the comment counter will not work.

请注意,您必须将类包装在 div 中,否则评论计数器将无法工作。

回答by Johan

Graph API example using jquery:

使用 jquery 的图形 API 示例:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
$(function(){

    $.ajax({
        url: 'http://graph.facebook.com/http://www.google.com',
        dataType: 'jsonp',
        success: function(data) {
             alert("comments: " + data.comments);
       }
    });

});
</script>

回答by Manvel

For an wordpress post u can use like <fb:comments-count href=<?php the_permalink();?>></fb:comments-count> awesome comments

对于 wordpress 帖子,您可以使用像 <fb:comments-count href=<?php the_permalink();?>></fb:comments-count> awesome comments