我正试图在<div id="comments">
必须通过Facebook查询语言(FQL)。这篇文章几乎正是我所需要的: Facebook Graph Api url comments and shares count doesn't work anymore
但是如何将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 :(得分:1)
我是这样做的,用这样的喜欢来更新我的div
$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);
}
});
对我来说就像一个魅力。
答案 1 :(得分: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>