Im trying to get access_token from pinterest api but getting this error.
'grant_type' is a required property
I'm using this login url:
https://www.pinterest.com/oauth/?client_id=APPID&redirect_uri=REDURL&response_type=code&scope=pins:write&state=eer
Redirect url have this code, which throws the error.
$vars = array(
"grant_type" => "authorization_code",
"code" => $_GET["code"],
"redirect_uri" => REDURL
);
$headers = [
'Authorization: Basic '.base64_encode("APPID:SECRET"),
'Content-Type: application/x-www-form-urlencoded'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api.pinterest.com/v5/oauth/token");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$vars);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec ($ch);
curl_close ($ch);
print $result;
I'm trying to follow this: https://developers.pinterest.com/docs/getting-started/authentication/
CodePudding user response:
Manual says about CURLOPT_POSTFIELDS
,
if value is an array, the
Content-Type
header will be set tomultipart/form-data
.
That appears to be colliding with the application/x-www-form-urlencoded
you are trying to send here.
Pass the data as a URL-encoded string instead, using http_build_query
.