从fb:评论小部件(Facebook)检索评论数 [英] Retrieving comment count from fb:comments widget (Facebook)

查看:98
本文介绍了从fb:评论小部件(Facebook)检索评论数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的FQL看起来像:

  SELECT count FROM comments_info WHERE xid =...

当我通过PHP尝试请求时,我收到以下错误:

 未捕获异常:604:没有有效的app_id 

PHP:

  $ facebook = new Facebook(array(
'appId'=>'...',
'secret'=>'...' ,
'cookie'=> true
));
$ result = $ facebook-> api(array(
'method'=>'fql.query',
'query'=>'SELECT count FROM comments_info WHERE xid = '。[...]。'''
));

appId 秘密我从Facebook开发者应用程序中的应用页面复制。



同样,当我使用JS API时,如: p>

  var query = FB.Data.query('SELECT count FROM comments_info WHERE xid ='+ [...] +' ); 
query.wait(function(rows){});

...我在JSONP响应中收到相同的错误:

  FB.ApiServer._callbacks.f2ba554518({error_code:604,error_msg:无效app_id,request_args:[{键:access_token,value:[我的APP ID] | [实际访问权限]},{key:api_key,value:[我的APP ID, ,{ 键: 回调, 值: FB.ApiServer._callbacks.f2ba554518},{ 键: 格式, 值: JSON串},{ 钥匙: method,value:fql.multiquery},{key:queries,value:{\index_comments_info_xid\:\select xid,count from comments_info where xid = \\\ [...] \\\ \ }},{ 键: SDK, 值: 袋鼠}]}); 

我甚至尝试重新创建该应用程序多次。



在这一点上,我投入了更多的时间比我想要承认:)
所以,如果有任何人有这个问题的经验,我会非常感谢 - Facebook的文档根本没有帮助,他们的开发论坛几乎已经死了。

解决方案

哎呀, 无效的app_id并不意味着我的应用程序ID无效 - 这意味着我需要在我的FQL查询中指定一个app_id,如文档页面



以下是获取评论数量的工作PHP示例:

  require_once('facebook.php'); 
$ facebook = new Facebook(array(
'appId'=>'[...]',
'secret'=>'[...]'
));
尝试{
$ result = $ facebook-> api(array(
'method'=>'fql.query',
'query'=& count FROM comments_info WHERE app_id ='。$ facebook-> getAppId()。'AND xid ='。[...]。'''
));
} catch(FacebookApiException $ e){
error_log($ e);
}


I've tried using both the JavaScript and PHP SDKs, but I can't solve this simple problem.

My FQL looks like:

SELECT count FROM comments_info WHERE xid="..."

When I attempt the request through PHP, I get the following error:

Uncaught Exception: 604: No valid app_id

PHP:

$facebook = new Facebook(array(
    'appId' => '...',
    'secret' => '...',
    'cookie' => true
));
$result = $facebook->api(array(
    'method' => 'fql.query',
    'query' => 'SELECT count FROM comments_info WHERE xid="'.[...].'"'
));

The appId and secret I copied from the application page in the Facebook Developer app.

Similarly, when I use the JS API, as in:

var query = FB.Data.query('SELECT count FROM comments_info WHERE xid="' + [...] + '"');
query.wait(function(rows){});

... I get the same error in the JSONP response:

FB.ApiServer._callbacks.f2ba554518({"error_code":"604","error_msg":"No valid app_id","request_args":[{"key":"access_token","value":"[MY APP ID]|[THE ACTUAL ACCESS TOKEN]"},{"key":"api_key","value":"[MY APP ID, AGAIN]"},{"key":"callback","value":"FB.ApiServer._callbacks.f2ba554518"},{"key":"format","value":"json-strings"},{"key":"method","value":"fql.multiquery"},{"key":"queries","value":"{\"index_comments_info_xid\":\"select xid,count from comments_info where xid=\\\"[...]\\\"\"}"},{"key":"sdk","value":"joey"}]});

I even tried recreating the application several times.

At this point, I've invested more hours than I'd care to admit :) So, if anyone has experience with this problem, I'd be very appreciative — Facebook's documentation is no help at all, and their dev forums are pretty much dead.

解决方案

Oops... bit of facepalm. "No valid app_id" doesn't mean my application id is invalid — it means I need to specify an app_id in my FQL query, as indicated on the documentation page.

Here's a working PHP example for getting the comment count:

require_once('facebook.php');
$facebook = new Facebook(array(
    'appId' => '[...]',
    'secret' => '[...]'
));
try {
    $result = $facebook->api(array(
        'method' => 'fql.query',
        'query' => 'SELECT count FROM comments_info WHERE app_id='.$facebook->getAppId().' AND xid="'.[...].'"'
    ));
} catch (FacebookApiException $e) {
    error_log($e);
}

这篇关于从fb:评论小部件(Facebook)检索评论数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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