簡體   English   中英

Disqus OAuth無效授予

[英]Disqus OAuth Invalid Grant

當我嘗試將OAuth與Disqus結合使用時,我一直收到此錯誤:

{"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();

誰能提供任何指示?

弄清楚了。 文檔在這里:

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

但是問題出在錯誤的api錯誤消息中。 請求授權時,用於獲取代碼的重定向uri必須完全相同。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM