facebook-sdk icon indicating copy to clipboard operation
facebook-sdk copied to clipboard

Batch requests

Open honi opened this issue 12 years ago • 1 comments

Is there a way to issue batch requests?

I've tried get_objects() which successfully retrieves several objects. But I can't seem to retrieve in one request several object/connection.

For example, if ['1','2'] are album ids, get_objects(['1','2']) successfully gives me those 2 albums. But I can't seem to do something like get_objects(['1/photos','2/photos'])

honi avatar Apr 25 '12 01:04 honi

The library does not currently have any explicit methods for batch API requests (the get_objects method only returns multiple objects, not "connections" like an album's photos), but it is possible to construct them.

Using the PHP code on the Facebook blog post announcing batching, I was able to construct this Python example:

>>> from facebook import GraphAPI
>>> graph = GraphAPI("access-token-goes-here")
>>> batched_requests = '[{"method":"GET","relative_url":"me"},{"method":"GET","relative_url":"me/friends?limit=50"}]'
>>> graph.request("", post_args = {"batch":batched_requests})
[redacted information about Martey and 50 of his friends]

I could see that a method to make this easier, or a way to put GraphAPI objects into "batch mode" (where all calls are stored, and sent as a batch request when needed) would be useful, so I will keep this open.

martey avatar May 07 '12 12:05 martey