Batch request query
-
13-03-2021 - |
Question
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:
- Set the access token as a separate parameter, not included as part of the
relative_url
attribute in the JSON payload. - Don't include the
message
as part of therelative_url
. Create abody
attribute instead and passmessage=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'
OTHER TIPS
The urls passed in the batch need to be urlencoded.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow