I am using Graph API https://developers.facebook.com/docs/reference/api/#publishing with PHP SDK and I would like to send some data via HTTP POST method, as it’s mentioned in documentation (e.g. add comment).
At https://developers.facebook.com/docs/reference/api/batch/ they say I should encode the body of HTTP POST request as …should be formatted as a raw HTTP POST body string, similar to a URL query string. I can’t get the combination of PHP functions to get this to work. In the example they claim following should work:
"body": "message=Test status update"
Well, that works. But what if I need to add other params? And how should be this string encoded? E.g. I have this:
$data = array('name' => 'Gargamel', 'occupation' => 'Freelancing Smurf Hunter');
How should I process it to get required format? Following does NOT work:
$batch = array();
$query = array(
'method' => 'POST',
'relative_url' => '/forrest/full/of/smurfs',
'body' => urldecode(http_build_query($data)),
);
$batch[] = $query;
$responses = $this->api('/?batch=' . json_encode($batch, JSON_HEX_AMP), 'POST');
I explored half of the Internet, but I can’t find any more specific information about the format than the one mentioned above (raw HTTP POST similar to a URL query string).
Thanks for any suggestions!
using this: http://forum.developers.facebook.net/viewtopic.php?pid=331343#p331343