引用/转义相关fql查询的in子句的jsonpath元素 [英] Quoting/escaping jsonpath elements for in clause of dependent fql queries
问题描述
我使用Facebook php sdk,试图获取别人对每个人在墙上张贴的每条帖子的评论列表.我在批处理API请求中使用FQL,如下所示:
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');
我从fb得到以下答复:
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..."}]}
很明显,post_ids需要加引号,实际上,使用相同的查询fb图api资源管理器,在IN子句中加引号的post_ids,我得到的结果就很好.
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.
**由于post_id是字符串(不是整数),因此如何在依赖的Batch API FQL查询的上下文中在引号周围加上引号,以使它们成为FQL IN子句的适当参数? **
**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? **
推荐答案
有点晚了,最有可能,但是作为替代,FQL 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/
您为查询创建JSON映射,然后将它们一起发送出去:
You make a JSON map of the queries, and send them off together:
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中找到针对此问题的解决方案,如果有发现,我将进行编辑.
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)
这篇关于引用/转义相关fql查询的in子句的jsonpath元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!