问题
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? **
回答1:
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:
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
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)
回答2:
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}' )");
来源:https://stackoverflow.com/questions/8171319/quoting-escaping-jsonpath-elements-for-in-clause-of-dependent-fql-queries