4

I have a user database from facebook. I want to get their data (interests and friends birthdays) using batch request. Now I can make 1 batch request for 1 user. But considering the no. of users in my app is huge definately it will reach a limit.

I want to know if there is any way to get multiple users data in a batch request

I tried the following but it didn't work

"access_token": "USER_A_ACCESS_TOKEN", batch=[ {"method": "GET", "access_token": "USER_A_ACCESS_TOKEN", "relative_url": "me/friends"}, {"method": "GET", "access_token": "USER_B_ACCESS_TOKEN", "relative_url": "me/friends"} ]

For userB access token also i get results for user A access token

Anuj Batra
  • 81
  • 2
  • 6

1 Answers1

6

According to the documentation on the batch requests page

The Batch API is flexible and allows individual requests to specify their own
access tokens as a query string or form post parameter. In that case the top
level access token is considered a fallback token and is used if an individual
request has not explicitly specified an access token.

Rewriting your original attempt should be like this

curl -F "access_token=USER_A_ACCESS_TOKEN" -F 'batch=[{"method": "GET", "relative_url": "me/friends?access_token=USER_A_ACCESS_TOKEN"}, {"method": "GET", "relative_url": "me/friends?access_token=USER_B_ACCESS_TOKEN"}]'

The original USER_A_ACCESS_TOKEN will be used as a fallback if there is an error with any of the other access_tokens

bloveless
  • 4,272
  • 1
  • 16
  • 13
  • 3
    Note that Facebook's docs claim that you can also include the access_token in the "json" portion (e.g. within each logical request within the `batch` JSON). Unfortunately, there appears to be a long-lived bug in the Graph API that prevents this from working. (http://stackoverflow.com/q/10396911/114558) So, the approach shown here, in which the `access_token` is appended to the URL, seems to be the only working configuration. – rinogo Feb 12 '15 at 06:52