将代码更改为访问令牌会出现此错误:
错误:{“status”:403,“message”:“禁止”}
这是我的代码:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,"grant_type=authorization_code&client_id=4853355452345362719&client_secret=deb78310995ec1cf00918a5e688e2148e6043bd640ab16f0f7ecd7543b4ac764&code=".$code);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result =curl_exec ($ch);
curl_close($ch);
print_r($result);
答案 0 :(得分:1)
首先,您需要生成访问令牌。这可以完成CURLing以下URL:
"https://api.pinterest.com/oauth?response_type=code&redirect_uri={$callBackUrl}&client_id={$clientId}&scope=read_public,write_public"
这将返回授权代码,然后您可以使用此代码生成访问令牌:https://api.pinterest.com/v1/oauth/token
有这些参数。
$url = "https://api.pinterest.com/v1/oauth/token";
$body = "grant_type=authorization_code&client_id={$clientId}&client_secret={$clientSecret}&code={$code}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
$content = curl_exec($ch);
curl_close($ch);
$data = json_decode($content, true);
答案 1 :(得分:0)
403 Forbidden通常会建议权限错误。我敢打赌,远程API无法识别您发送的代码