HTTP 요청뿐만 아니라 API도 처음 사용하기 때문에 몇 가지 문제가 있습니다. 토큰 정보를 GET 요청에서 얻은 후에 API로 전달하는 방법을 잘 모르겠습니다. imgur API는 요청한 토큰을 전달할 수 없기 때문에 http://api.imgur.com/auth의 세 끝점이 필요하다고 말합니다.토큰 정보를 요청을 통해 Imgur API에서받은 후 소급하여 전달합니다.
모듈 설명서가 너무 모호합니다. https://github.com/maraujop/requests-oauth
다음은 인증을 성공적으로 통과 한 코드이지만 http://pastebin.com/19hnBy1C이라는 html 페이지를 반환합니다.
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는 몇 가지 트위터를 통해 좋은 아이디어를 얻을 수 있다고 제안하지만, 내가 읽고있는 사람 : http://net.tutsplus.com/tutorials/php/how-to-authenticate-users-with-twitter-oauth/은 PHP이므로 내 머리 위로 조금 빗나간 다. 하고있어.
감사합니다. 다른 사람들에게, 해결책을 시도하기 전에 oauth를'0.4.0'으로 바르게 업데이트해라. – TankorSmash