[英]Php curl post request to pinterest not working
將代碼更改為訪問令牌會出現以下錯誤:
錯誤:{“狀態”:403,“消息”:“禁止”}
這是我的代碼:
$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);
首先,您需要生成一個訪問令牌。 可以通過以下URL進行CURL: "https://api.pinterest.com/oauth?response_type=code&redirect_uri={$callBackUrl}&client_id={$clientId}&scope=read_public,write_public"
這將返回授權碼,然后您可以使用此代碼通過以下URL來使用以下URL生成訪問令牌: https://api.pinterest.com/v1/oauth/token
: 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);
403 Forbidden通常會提示權限錯誤。 我敢打賭,遠程API無法識別您正在發送的代碼
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.