Reputation: 31
I using below command to get access token
curl -X POST https://api.pinterest.com/v5/oauth/token
--header 'Authorization: Basic {base64 encoded string made of client_id:client_secret}'
--header 'Content-Type: application/x-www-form-urlencoded'
--data-urlencode 'grant_type=authorization_code'
--data-urlencode 'code={YOUR_CODE}'
--data-urlencode 'redirect_uri=http://localhost/'
I am getting
{"code":2,"message":"Authentication failed."}
client_id and secret are correct. Any pointers will be helpful.
Regards, Rita
Upvotes: 0
Views: 818
Reputation: 64
It has been some time that you've asked dont know if you've already find out but this would help to others as well.
There is some informatical issues in pinterest doc.
For e.g
$vars = array(
"grant_type" => "authorization_code",
"code" => <code_you_get_from_step_one>,
"client_id" => env("PINTEREST_CLIENT_ID"),
"client_secret" => env("PINTEREST_CLIENT_SECRET"),
"redirect_uri" => 'http://localhost:8000/auth/pinterest/callback'
);
$headers = [
'Authorization: Basic '.base64_encode("$client_id:$client_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,http_build_query($vars));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec ($ch);
curl_close ($ch);
dd($result);
2)If you're attempting with like above curl request As CBroe has mentioned in here As Manual says about CURLOPT_POSTFIELDS "if value is an array, the Content-Type header will be set to multipart/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.
curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($vars));
Hope this is going to be helpful for other developers who are trying to integrate pinterest oauth.
Upvotes: 0