Facebook API - 通过FQL进行评论 [英] Facebook API - comment count via FQL

查看:128
本文介绍了Facebook API - 通过FQL进行评论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在中显示Facebook评论数量
$ b

它必须通过Facebook查询语言(FQL)。这个帖子几乎是我需要的:
Facebook Graph Api url评论和分享计数不再工作



但是如何显示 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 ''评论('+ jsonp.data.comment_count +')');
} else {
$('body')。find('#comments')。html('Comments(0)') ;
}
}
});
});


解决方案

对于我来说,



我使用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>


I'm trying to display Facebook comment counts in <div id="comments">

It has to be via Facebook Query Language (FQL). This post is almost exactly what I need: Facebook Graph Api url comments and shares count doesn't work anymore

But how do I display the comment_count (from the query) into a div? i.e. how do I process that data? So far, I have:


$(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)');
   }
  }
 });
});

解决方案

For my part,

I used php code to get the comment count via fql. First, you need to download the facebook php sdk and load it at the top of your page:

require_once("src/facebook.php");

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

  $facebook = new Facebook($config);

Then, the fql query:

$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'];

So, $cmcount is now your comment counts, put it directly in your html code:

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

这篇关于Facebook API - 通过FQL进行评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆