我使用下面的命令获取访问令牌
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和secret正确。任何提示都会有帮助的。
问候,丽塔
你已经问了一段时间了,我不知道你是否已经找到了,但这也会对其他人有所帮助。
pinterest文档中有一些信息问题。
- 你需要传递客户端id和客户端秘密到这个curl请求与其他必要的参数。 如
$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)如果你正在尝试像上面那样的curl请求,正如CBroe在这里提到的,正如Manual所说的CURLOPT_POSTFIELDS "如果value是一个数组,Content-Type头将被设置为multipart/form-data ">
这似乎与您试图在这里发送的application/x-www-form-urlencoded冲突。
使用http_build_query将数据作为url编码的字符串传递。
curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($vars));
希望这对其他试图整合pinterest oauth的开发人员有帮助。