Facebook: field expansion in batch requests ->

145 Views Asked by At

How can I define the requested fields for the 2nd part of my batch request?

Example:

[
  {
    "method": "GET",
    "name": "get-friends",
    "relative_url": "me/friends?limit=5",
    "omit_response_on_success": false
  },
  {
    "method": "GET",
    "relative_url": "?ids={result=get-friends:$.data.*.id}"
  }
]

This works so far. But now I want to define the requested fields for the 2nd part.

When I add &fields=address ("relative_url": "?ids={result=get-friends:$.data.*.id}&fields=address") I get a "Batch parameter must be a JSON array" exception :-(

Ralph

1

There are 1 best solutions below

2
On BEST ANSWER

I get a "Batch parameter must be a JSON array" exception

That probably just means your query could not be understood, because you invalidated the syntax somehow. & has a special meaning in a URL, so you most likely just need to encode it properly.

URL-encode the whole value of the batch parameter (so basically your whole JSON string that you got from your object.)

(What function/method to use for that, depends on how you build your request, resp. in what language. PHP has urlencode, JavaScript has encodeURIComponent, etc.)