2014-01-10 2 views
0

내가 Disqus에로의 OAuth를 사용하려고 할 때이 오류가 점점 계속 :Disqus에 OAuth를 잘못된 그랜트

$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 :

{"error_description":"Invalid parameter: redirect_uri","error":"invalid_grant"} 

내 코드 this- 예 1과 같다 :

$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(); 

누구든지 방향을 제시 할 수 있습니까?

+0

인증 키가 괜찮습니까? – Mave

+0

괜찮습니까? –

+0

Disqus에서 제공 한 올바른 것입니까? 또한 redirect_uri를 생략하십시오. – Mave

답변

0

알아 냈어. 문서는 여기에 있습니다 :

http://tools.ietf.org/html/rfc6749#section-4.1.3

그러나 문제는 나쁜 API 오류 메시지에서 유래한다. 코드를 가져 오는 리디렉션 URI는 인증을 요청할 때 정확히 동일한 URI이어야합니다.