-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with POST json data #54
Comments
This library was not prepared to POST a data in JSON format using CURL Here's a working sample: $params = array(
"firstName" => "John",
"lastName" => "Doe",
"email1" => array(
"value" => "[email protected]",
"default" => true
)
);
$header = array(
'Content-Type' => 'application/json;charset=utf-8',
'Content-Length' => strlen(json_encode($params))
);
$response = $client->fetch('https://graph.facebook.com/me', $params, 'PUT', $header);
var_dump($response); Modifications From this code: if(is_array($parameters) && self::HTTP_FORM_CONTENT_TYPE_APPLICATION === $form_content_type) {
$parameters = http_build_query($parameters, null, '&');
}
$curl_options[CURLOPT_POSTFIELDS] = $parameters; Replace it with this code: if(strpos($http_headers['Content-Type'], 'x-www-form-urlencoded') !== false) {
if(is_array($parameters) && self::HTTP_FORM_CONTENT_TYPE_APPLICATION === $form_content_type) {
$parameters = http_build_query($parameters, null, '&');
}
$curl_options[CURLOPT_POSTFIELDS] = $parameters;
} else {
$curl_options[CURLOPT_POSTFIELDS] = json_encode($parameters);
if (is_array($parameters) && count($parameters) > 0) {
$url .= '?' . http_build_query($parameters, null, '&');
} elseif ($parameters) {
$url .= '?' . $parameters;
}
} |
By now, you can also pass the |
As described at: adoy#54 (comment)
Hi
I am using the snippet code below for POST an new event, but failed with 400 Error. just wondering if I missed something or can you please provide me the sample code of POST data?
My email address is: [email protected]
setAccessTokenType(2,$client->getClientSecret()); $param ='{"event":{"name":"ACF API Test","intro":"protect our environment","start_time":"2016-02-08T17:00:00-00:00","end_time":"2016-02-08T19:00:00-00:00","status":"unlisted"}}'; $response = $client->fetch($this->nb_baseapiUrl . '/api/v1/events/', $param, 'POST'); print_r($response); ?>Regards
Stanley
The text was updated successfully, but these errors were encountered: