为依赖的fql查询的in子句引用/转义jsonpath元素

时间:2011-11-17 17:09:23

标签: facebook-graph-api facebook-fql jsonpath facebook-batch-request

使用facebook php sdk,我正在尝试获取其他人发给某人墙的帖子的评论列表。我在Batch API请求中使用FQL,如下所示:

$getStream   = urlencode("method/fql.query?query=SELECT post_id, actor_id, target_id, source_id,viewer_id, message FROM stream WHERE app_id= '' and message != '' and source_id=$fbprofileId and target_id=$fbprofileId and is_hidden=0 limit 100");
$getComments = urlencode("method/fql.query?query=select object_id, post_id, fromid, time, text, id, likes, comments, user_likes, is_private from comment where post_id in({result=get-stream:$.*.post_id})");
$queries = array(
                     array('method'                   => 'POST',
                           'omit_response_on_success' => false,
                           'name'                     => 'get-stream',
                           'relative_url'             => $getStream),
                     array('method'                   => 'POST',
                           'omit_response_on_success' => false,
                           'name'                     => 'get-comments',
                           'relative_url'             => $getComments)
                );
return $this->fbApi->api('?batch='.json_encode($queries), 'POST');

我从fb获得以下回复:

 {"error_code":601,"error_msg":"Parser error: unexpected '_1831955838114' at position 63.","request_args":[{"key":"method","value":"fql_query"},{"key":"format","value":"json"},{"key":"_fb_batch_child_request","value":"1"},{"key":"query","value":"select user_id, object_id from like where post_id in(1216940586_1831955838114,1216940586_1831891396503,1216940586_1831423824814,1216940586_1828915522108,1216940586_1822006149378,1216940586_1820687356409,1216940586_1813971228510,1216940586_1809392594047,1216940586_1795412004541,1216940586_1795177518679)"},{"key":"_fb_url","value":"method\/fql.query"},{"key":"access_token","value":"AAAC02IZB..."}]}

似乎很清楚post_ids需要引用,事实上,使用相同的查询fb graph api explorer并在IN子句中引用post_ids我得到的结果很好。

**由于post_id是字符串(不是整数),如何在它们周围加上引号,使它们在依赖的Batch API FQL查询的上下文中成为FQL IN子句的正确参数? **

2 个答案:

答案 0 :(得分:0)

有点晚,很可能,但作为替代方案,FQL api支持正确处理类型的批处理查询:http://developers.facebook.com/docs/reference/fql/

您制作查询的JSON地图,并将它们一起发送:

https://graph.facebook.com/fql?q={
  "friends":"SELECT uid2 FROM friend WHERE uid1=me()",
  "with_birthdays":"SELECT uid, name FROM user WHERE uid IN (select uid2 from #friends) and birthday_date"
}&access_token=yourToken29873

显然编码这些查询(为了更容易阅读而保留未编码的信息)。我将在批处理API中查看是否可以找到解决方案,但如果找到任何内容,我会编辑。

(编辑:这里没有运气,对不起。已经尝试了很多,但我得到的没有错误,没有结果或解析器错误)

答案 1 :(得分:-1)

这似乎是解决方案:'{result = get-stream:$。*。post_id}'

应该如此 $getComments = urlencode("method/fql.query?query=select object_id, post_id, fromid, time, text, id, likes, comments, user_likes, is_private from comment where post_id in( '{result=get-stream:$.*.post_id}' )");