0
我不斷收到這個錯誤,當我嘗試使用OAuth與Disqus:Disqus OAuth的授權無效
{"error_description":"Invalid parameter: redirect_uri","error":"invalid_grant"}
我的代碼看起來像這個 - 例1:
$oauth2token_url = 'https://disqus.com/api/oauth/2.0/access_token/';
$redirect_uri = 'http://www.example.com/';
$clienttoken_post = array(
"grant_type" => 'authorization_code',
"client_id" => PVConfiguration::getConfiguration('disqus') -> public_key,
"client_secret" => PVConfiguration::getConfiguration('disqus') -> private_key,
"redirect_uri" => $redirect_uri,
"code" => $this -> registry -> get['code']
);
$curl = curl_init($oauth2token_url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $clienttoken_post);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$json_response = curl_exec($curl);
curl_close($curl);
print_r($json_response);
或者這 - 例2:
$url = 'https://disqus.com/api/oauth/2.0/access_token/';
$fields = array(
'grant_type' => 'authorization_code',
'client_id' => PVConfiguration::getConfiguration('disqus') -> public_key,
'client_secret' => PVConfiguration::getConfiguration('disqus') -> private_key,
'redirect_uri' => 'http://www.example.com/',
//'scope' => 'read,write,email',
'code' => $this -> registry -> get['code'],
);
$fields_string = '';
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
print_r($result);
exit();
任何人都可以提供任何方向嗎?
你確定授權密鑰沒問題嗎? – Mave
你是什麼意思? –
它們是Disqus提供的正確的嗎?此外,請嘗試刪除redirect_uri。 – Mave