2013-03-07 5 views
9

Redditアクセストークンを更新できません。Reddit OAuth 2.0アクセストークンを更新できません

私はhttps://ssl.reddit.com/api/v1/access_token

Content-Type: application/x-www-form-urlencoded 
Authorization: ##### 
client_secret=#####&grant_type=refresh_token&client_id=#####&refresh_token=##### 

に次のリクエストを送信すると、私は状況200を取得するが、内容は{"error": "invalid_request"}です。

OAuth 2.0 specReddit specによれば、私はすべてのことを正しく行います。

私はまた、client_idclient_secretを使わずに同じ結果を試しました。

何か不足していますか?

答えて

20

RedditのOAuth実装は、本当にユニークです(いい方法ではありません)。

Redditのにリフレッシュトークンに必要なパラメータは、次のとおり

  1. client_secret
  2. grant_type(= refresh_token)
  3. refresh_token
  4. scope
  5. state
  6. 0 CLIENT_ID
  7. REDIRECT_URI

またの基本的なHTTP認証ヘッダーは、ログインやパスワードなどのclient_secretとしてをCLIENT_ID必要があります。

私の要求に欠けていたものを理解するために、redditのsource codeを検索しなければなりませんでした。そんなに開発時間がかかってしまいました。

+0

このバグは修正されました。私はgrant_typeとrefresh_tokenパラメータが必要です。リフレッシュトークンがclient_idと同じアプリ用でない場合は400を返します – Nathan

2

さらに明示的な回答をお探しの方は

ここで私はこれをPHPで行っています。

$authorizeUrl = 'https://ssl.reddit.com/api/v1/access_token'; 
    $clientId = "YOUR_CLIENT_ID"; 
    $clientSecret = "YOUR_CLIENT_SECRET"; 

    $post = array(
     "client_id" => $clientId, 
     "client_secret" => $clientSecret, 
     "grant_type" => "refresh_token", 
     "refresh_token" => "STORED_REFRESH_TOKEN_VALUE", 
     "scope" => "identity", 
     "state" => "WHATEVER_VALUE", 
     "duration" => "temporary",   
     "redirect_uri" => "https://example.com/reddit", 
    ); 

    $payload = http_build_query($post); 

    $ch = curl_init($authorizeUrl); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded')); 
    curl_setopt($ch, CURLOPT_HEADER, 1); 
    curl_setopt($ch, CURLOPT_USERPWD, $clientId . ":" . $clientSecret); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 30); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
    $result = curl_exec($ch); 
    curl_close($ch);   

    print_r($result); 
関連する問題