2011-10-04 73 views
11

我知道兩種方法獲得的評論在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/ –

回答

11

由於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,現在可以工作。 :) –

12

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

29

您還可以得到有效的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

-1

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

相關問題