2012-04-20 4 views
0

私はAPIを使用するのが初めてで、HTTPリクエストもありません。トークン情報をGETリクエストから取得した後、APIに渡す方法がわかりません。 imgur APIには、http://api.imgur.com/authという3つのエンドポイントが必要だと書かれていますが、要求されたトークンを渡すことができないため、2番目のものまでしか受け取りません。Imgur APIからrequest-oauthを使用して遡及的にトークン情報を渡す

モジュールのドキュメントは、 https://github.com/maraujop/requests-oauth

これは私が書いたコードで、認証に成功したはずですが、htmlページhttp://pastebin.com/19hnBy1Cを返します。

import requests 
from oauth_hook import OAuthHook 
import cgi 

OAuthHook.consumer_key = 'XXXXXXX' 
OAuthHook.consumer_secret = 'YYYYY' 


#just in case 
oauth_hook = OAuthHook(header_auth=True) 

#request the tokens, using the keys set above 
r = requests.get(url='https://api.imgur.com/oauth/request_token', hooks={'pre_request': oauth_hook,}) 

#parse the lsit 
tokenList = cgi.parse_qs(r.content) 

token = tokenList['oauth_token'] 
tokenSecret = tokenList['oauth_token_secret'] 

#this is where I'm not sure what to do, 
#I create a new hook with the tokens I received 
oauth_hook = OAuthHook(access_token=token[0], access_token_secret=tokenSecret[0]) 

#send the GET request 
r = requests.get(url='https://api.imgur.com/oauth/authorize', hooks={'pre_request': oauth_hook,}) 

#this is that HTML that requires me to enter account info, how do I do that in python? 
print r.content 

#this is the next step, which, if you uncomment the last print, shows that the auth failed. 
r = requests.get(url='https://api.imgur.com/oauth/access_token', hooks={'pre_request': oauth_hook,}) 

#print r.text 

続行するにはどうすればよいですか?

authorize apiにPOSTを送信して、ユーザー名/パスワードをデータまたはパラメータとして送信できると思ったが、動作していないようだ。

Imgur APIは、私が読んでいるものの、良いアイデアを得るためにいくつかのtwitterドキュメントを見ています。http://net.tutsplus.com/tutorials/php/how-to-authenticate-users-with-twitter-oauth/はPHPですので、私の頭の中に少しあります。している。

答えて

1

私はrequest-oauthの著者です。私は最近、このアプリのバージョン0.4.0をリリースし、OAuthの新人を手助けするためのドキュメントを改善しました。

ここ

は、うまくいけば、あなたの質問への答えです: https://github.com/maraujop/requests-oauth#3-legged-authorization

答えることはそう長く取って申し訳ありません。

+0

よろしくお願い致します。他の人に注意して、解決策を試す前にoauthを '0.4.0'に正しく更新してください! – TankorSmash

関連する問題