2013-01-17 30 views
1

我想顯示的Facebook評論數評論計數。這篇文章是幾乎正是我需要的: Facebook Graph Api url comments and shares count doesn't work anymoreFacebook的API - 在<code><div id="comments"></code></p> <p>它必須通過Facebook查詢語言(FQL)通過FQL

但是我怎麼顯示comment_count(從查詢)到div?即我如何處理這些數據?到目前爲止,我有:


$(function(){ 
$.ajax({ 
    url: 'https://graph.facebook.com/fql?q=SELECT%20comment_count%20FROM%20link_stat%20WHERE%20url=%27e', 
    dataType: 'jsonp', 
    success: function(data) { 
    if(data.comment_count) 
    { 
    $('body').find('#comments').html('Comments ('+jsonp.data.comment_count+')'); 
    }else{ 
    $('body').find('#comments').html('Comments (0)'); 
    } 
    } 
}); 
}); 
+0

這個url是完美嗎? – Hemc

+0

嗨! - 網址只是一個例子:一個完整​​的網址,例如:https://graph.facebook.com/fql?q=SELECT%20comment_count%20FROM%20link_stat%20WHERE%20url=%27google.com%27 – melusinefile

回答

1

我做了這樣的更新我的分度,喜歡算這樣

$fql = "SELECT url, normalized_url, share_count, like_count, comment_count, "; 
    $fql .= "total_count, commentsbox_count, comments_fbid, click_count FROM "; 
    $fql .= "link_stat WHERE url = '".$url."'"; 

$j.ajax({ 
      url: 'https://api.facebook.com/method/fql.query?format=json&query=<?php echo urlencode($fql);?>', 
      dataType: 'jsonp', 
      success: function(data) 
      { 
$j(".comment_count").html(data.comment_count); 
} 
}); 

作品對我來說就像一個魅力。

+0

所以你說我需要做的就是替換 - url ='「。$ url。」'「;與我的網址?例如(url ='http://google.com')?(試過了,它沒有工作。謝謝! – melusinefile

+0

基本上,爲了澄清,我需要在div中顯示comment_count這個示例鏈接:https://graph.facebook.com/fql?q=SELECT%20comment_count%20FROM%20link_stat% 20WHERE%20url =%27google.com%27 – melusinefile

+0

.comment_count是div的類,它將用註釋數替換div的html。 – 2013-02-07 07:59:12

1

就我而言,

我用PHP代碼獲得通過FQL評論數。首先,你需要下載Facebook的PHP SDK,並加載它在你的頁面的頂部:

require_once("src/facebook.php"); 

    $config = array(
    'appId' => 'YOUR_APP_ID', 
    'secret' => 'YOUR_SECRET_KEY', 
); 

    $facebook = new Facebook($config); 

然後,FQL查詢:

$url = 'http://www.yoururl.com/; 

$fquery = 'SELECT comment_count, share_count, like_count FROM link_stat WHERE url = "'.$url.'"'; 
$fparam = array('method' => 'fql.query', 'query' => $fquery); 
$fql = $facebook->api($fparam); 

$cmcount = $fql[0]['comment_count']; 

所以,$ cmcount現在您的評論數,把它直接放在你的html代碼中:

<div id="comments"> 
<?php echo $cmcount; ?> 
</div> 
+0

嘗試使用'SELECT commentsbox_count'而不是'SELECT comment_count',它更準確! – pmrotule

相關問題