开发者

Can you batch search queries like graph.facebook.com/search?q=QUERY&type=OBJECT_TYPE?

In the documentation for batch requests with the graph api there are no examples of using a search query for the relative url. It should work just like other api calls but I'm getting an error and wondering if Facebook lets you batch search queries. So I'm batching some api calls using the php sdk like

$queries = array(
array('method' => 'GET', 'relative_url' => '/67226614422'),
array('method' => 'GET', 'relative_url' => '/140959058191'),
);
$this->test(json_enco开发者_开发技巧de($queries));

$objs = $fb->api('/?batch='.json_encode($queries), 'POST');

Which works great. But if i try to use search?q=QUERY&type=page as the relative url like below

$queries = array(
array('method' => 'post', 'relative_url' => '/search?q=cornell&type=page'),
array('method' => 'GET', 'relative_url' => '/67226614422'),
array('method' => 'GET', 'relative_url' => '/140959058191'),
);

the sdk throws an error

Uncaught Exception: batch parameter must be a JSON array thrown in .../facebook.php

this is the encoded json:

[{"method":"post","relative_url":"\/search?q=cornell&type=page"},{"method":"GET","relative_url":"\/67226614422"},{"method":"GET","relative_url":"\/140959058191"}]


You need to url encode the relative_url if it has an ampersand in it.

Same goes if you are doing a POST request, and you have more than one parameter in the body you are sending.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜