为依赖 fql 查询的 in 子句引用/转义 jsonpath 元素
使用 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_ids 是字符串(不是整数),如何在它们周围加上引号,以使它们在依赖 Batch API FQL 查询的上下文中成为 FQL IN 子句的正确参数? **
Using the facebook php sdk, I am trying to get a list of comments for every post made to a person's wall by someone else. I'm using FQL in a Batch API request as follows:
$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');
I get the following response from 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..."}]}
It seems clear that the post_ids need to be quoted and in fact, using the same query fb graph api explorer with quoted post_ids in the IN clause i get results just fine.
**Since post_ids are strings (not ints), how do I put quotes around them to make them proper arguments to an FQL IN clause in the context of dependent Batch API FQL queries? **
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这很可能有点晚了,但作为替代方案,FQL api 支持正确处理类型的批处理查询: http://developers.facebook.com/docs/reference/fql/
您制作查询的 JSON 映射,并将它们一起发送:
显然对这些查询进行了编码(为了便于阅读而未编码)。我将看看是否可以在批处理 API 中找到此问题的解决方案,如果找到任何内容,我将进行编辑。
(编辑:这里运气不好,抱歉。已经尝试了很多,但我要么没有错误,没有结果,要么解析器错误)
It's a bit late, most likely, but as an alternative the FQL api supports batched queries that handle types correctly: http://developers.facebook.com/docs/reference/fql/
You make a JSON map of the queries, and send them off together:
Obviously encoding those queries (left unencoded for easier reading). I'm going to see if I can find a solution to this within the batch API though, I'll edit if I find anything.
(edit: no luck here, sorry. Have tried quite a bit, but I either get no error and no results, or parser errors)
这似乎是解决方案: '{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}')");
This seems to be the solution: '{result=get-stream:$.*.post_id}'
So it should be
$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}' )");