如何使用HTML5获得Facebook评论?

问题描述:

我知道两种方法获得的评论在Facebook上的号码:如何使用HTML5获得Facebook评论?

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

和...

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

但没有对HTML5解决方案的语义,有没有什么方法吗?

+0

你可以抓住数据从Facebook是,好了,从Facebook抓取数据的唯一途径。你需要使用他们的API之一来做到这一点,无论是JavaScript,PHP,红宝石,蟒蛇等... – Connor

+0

谢谢Connor,但fb:comments-count是一个插件。 http://developers.facebook.com/docs/reference/plugins/comments/ –

由于v2.3,它可以通过span,其已经具有天然display: inline;语义处理。

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

除非你使用div标签,否则它将不起作用。 – Pierre

+1

@Pierre,现在可以工作。 :) –

图形API例如使用jquery:

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

+1我喜欢API的图形;) –

+0

这是必须在最上面。 – sonnb

您还可以得到有效的HTML5 FB评论数是这样的:

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

FB了正确的号码会自动替换为 “0”。如果你把东西有没有像“真棒的意见”,将与评论的数量来代替,即“13”等

为了获得数量和使用自己的文字,做这样的事情:

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

请注意,您必须将您的课程封装在div中,否则注释计数器将无法使用。

+0

天才,谢谢! – TMC

对于WordPress邮寄u可以使用像<fb:comments-count href=<?php the_permalink();?>></fb:comments-count> awesome comments