带有file_get_contents的Facebook FQL返回空数组

时间:2014-05-17 08:10:58

标签: php facebook facebook-graph-api

我正在使用FQL脚本直接在我的网站上回复Facebook对我网站网址的评论。但是,有些网址返回一个空数组,即使我直接访问Facebook API,我也可以看到它们带有注释。这只发生在最新的网址上。这是我使用的代码:

$queries = array('q1' => 'select post_fbid, fromid, object_id, text, time from comment where object_id in (select comments_fbid from link_stat where url ="'.$url.'")',
             'q2' => 'select post_fbid, fromid, object_id, text, time from comment where object_id in (select post_fbid from #q1)',
             'q3' => 'select name, id, url, pic_square, username from profile where id in (select fromid from #q1) or id in (select fromid from #q2)',
             'q4' => 'select uid, first_name from user where uid in (select fromid from #q1) or uid in (select fromid from #q2)',
             );
$result = (file_get_contents('http://api.facebook.com/restserver.php?format=json-strings&method=fql.multiquery&queries='.urlencode(json_encode($queries)));

现在,如果我回显$ result变量,我会看到:

[{ “名称”: “Q1”, “fql_result_set”:[]},{ “名称”: “Q2”, “fql_result_set”:[]},{ “名称”: “Q3”, “fql_result_set” :[]},{“name”:“q4”,“fql_result_set”:[]}]

即使我在API网址(api.facebook.com等等)中看到fql_result_set已满。有人能解释我这种奇怪的行为吗? :-)

1 个答案:

答案 0 :(得分:0)

不推荐使用端点http://api.facebook.com。请改用https://graph.facebook.com。请参阅https://developers.facebook.com/docs/graph-api/making-multiple-requests/#fql作为参考。

此外,您需要确保查询之间的引用是正确的。查看https://developers.facebook.com/docs/graph-api/making-multiple-requests/#operations并阅读您可以使用的JSONPATH语法。

更改查询:

$queries = array('q1' => 'select post_fbid, fromid, object_id, text, time from comment where object_id in (select comments_fbid from link_stat where url ="'.$url.'")',
             'q2' => 'select post_fbid, fromid, object_id, text, time from comment where object_id in ({result=q1:$.data.*.post_fbid})',
             'q3' => 'select name, id, url, pic_square, username from profile where id in ({result=q1:$.data.*.fromid}) or id in ({result=q2:$.data.*.fromid})',
             'q4' => 'select uid, first_name from user where uid in ({result=q1:$.data.*.fromid}) or uid in ({result=q2:$.data.*.fromid})',
             );

我对您的疑问不理解:

  • q2或多或少是q1
  • 的副本
  • q3信息也可以通过改变q4
  • 来检索