phpfacebookfacebook-graph-apifacebook-batch-request

Batch request query


I am working with the batch request of the Facebook. I have tried the api call as shown below. Is there anything wrong here?

[{"method":"POST","relative_url": "xxxxxxxxx/apprequests?message=hello&access_token=xxxxxxxx|xxxxxxxxxxxxxxx"},{"method":"GET","relative_url": "xxxxxxxx/mutualfriends/xxxxxxxxx"}]

<HTML><HEAD><TITLE>400 Bad Request</TITLE>
</HEAD><BODY>
<H1>Method Not Implemented</H1>
Invalid method in request<P> 
</BODY></HTML>

here xxxxxx is the facebook userid and access_token=xxxxxx|xxxxxxxxxxx is facebook app access token.


Solution

  • I see a few problems:

    1. Set the access token as a separate parameter, not included as part of the relative_url attribute in the JSON payload.
    2. Don't include the message as part of the relative_url. Create a body attribute instead and pass message=hello as the value.

    e.g.

    curl -F 'access_token=XYZ' \
         -F 'batch=[{"method":"POST","relative_url":"xxxxxxxxx/apprequests", "body","message=hello"},{"method":"GET","relative_url": "xxxxxxxx/mutualfriends/xxxxxxxxx"}]'  'https://graph.facebook.com'