2012-08-14 275 views
1

我需要檢查PHP有多少喜歡顯示在Facebook Like Button中。如何檢索Facebook的喜歡數量喜歡按鈕代碼

由於某些原因,我不能只是執行一個FQL查詢來獲得喜歡的數量。我必須在FB Like Button html/js代碼上操作。

例子:

<div id="fb-root"></div> 
<script>(function(d, s, id) { 
    var js, fjs = d.getElementsByTagName(s)[0]; 
    if (d.getElementById(id)) return; 
    js = d.createElement(s); js.id = id; 
    js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1"; 
    fjs.parentNode.insertBefore(js, fjs); 
}(document, 'script', 'facebook-jssdk'));</script> 

<fb:like href="http://www.example.com" send="false" width="450" show_faces="false"></fb:like> 

我真的不想安裝和使用一些JS解釋以檢索喜歡的值。有沒有更簡單的方法來做到這一點?

+0

如果您嘗試從網站上的Facebook按鈕刮取喜歡的數量,那麼您不能。該數字存在於iframe中,因此XSS安全性將適用。使用API​​獲取類似數字的數字是微不足道的,但如果你不能,那聽起來你正在做一些違反Facebook TOS的事情。 – cpilko 2012-08-14 20:09:23

+0

你錯了。我可以 - 每個瀏覽器都能做到這一點,並且沒有任何問題。 – 2012-08-14 20:15:56

回答

0

您可以使用FQL獲取喜歡的數量。例如,我創建使用Like Button plugin creator tool這個喜歡按鈕:

<fb:like href="http://plooza.com" send="false" width="450" show_faces="true"></fb:like> 

然後我可以使用FQL喜歡的數量,使用Graph API Explorer作爲一個快速測試:

SELECT url, normalized_url, share_count, like_count, comment_count, total_count, commentsbox_count, comments_fbid, click_count FROM link_stat WHERE url="plooza.com" 

產量爲:

{ 
  "data": [ 
    { 
      "url": "plooza.com", 
      "normalized_url": "http://www.plooza.com/", 
      "share_count": 0, 
      "like_count": 2, 
      "comment_count": 0, 
      "total_count": 2, 
      "commentsbox_count": 0, 
      "comments_fbid": "1015079258276xxxx", 
      "click_count": 0 
    } 
  ] 
} 
+0

正如我寫的,我無法執行FQL查詢。 – 2012-08-14 19:41:12

+0

好吧,我誤解了。我以爲你想通過PHP(或GET)來做FQL來獲得類似按鈕的喜歡數,並且你不想使用js。如果您不能使用js或FQL,則可以使用Graph API,例如。 https://graph.facebook.com/122054155397 – 2012-08-14 19:49:17

+0

我也無法使用Graph API。 – 2012-08-14 19:58:40