我对连接到 API 和一般使用 OAuth2Service 还是很陌生。以下问题已经给我带来了一段时间的问题,我完全停止了。我的代码如下:
from rauth import OAuth2Service
OAUTH_CONSUMER_KEY = 'mykey'
OAUTH_SECRET = 'myecret'
request_token_url = 'https://api.login.yahoo.com/oauth/v2/get_request_token'
authorize_url = 'https://api.login.yahoo.com/oauth/v2/request_auth'
access_token_url = 'https://api.login.yahoo.com/oauth/v2/get_token'
yahoo = OAuth2Service(client_id=OAUTH_CONSUMER_KEY,\
client_secret=OAUTH_SECRET,\
name='yahoo',\
access_token_url=access_token_url,\
authorize_url=authorize_url,\
#request_token_url=request_token_url,\
base_url='https://api.login.yahoo.com/oauth/v2/')
print ('Visit this URL in your browser: ' + yahoo.get_authorize_url())
code = input('Enter code parameter (code=something) from URL: '
当我转到授权的 url 页面时,系统会提示我输入代码,但我不知道如何获取代码。
我从 rauth 页面 ( https://github.com/litl/rauth/blob/master/examples/github-cli.py )上的示例中获取了最后一部分,但我不明白关于我需要更改什么的评论'东西'也是。
我找到了一些使用 OAuth1Service 的示例,但是当我尝试使用 OAuth1 时总是收到以下错误
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\rauth\service.py", line 21, in process_token_request
return tuple(data[key] for key in args)
File "C:\Python34\lib\site-packages\rauth\service.py", line 21, in <genexpr>
return tuple(data[key] for key in args)
KeyError: 'oauth_token'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "yhandlertest.py", line 23, in <module>
rtoken, rtoken_secret = yahoo.get_request_token(params={'oauth_callback': CALL_BACK})
File "C:\Python34\lib\site-packages\rauth\service.py", line 244, in get_request_token
process_token_request(r, decoder, key_token, key_token_secret)
File "C:\Python34\lib\site-packages\rauth\service.py", line 24, in process_token_request
raise KeyError(PROCESS_TOKEN_ERROR.format(key=bad_key, raw=r.content))
KeyError: "Decoder failed to handle oauth_token with data as returned by provider. A different decoder may be needed. Provider returned: b'oauth_problem=consumer_key_unknown'
所以看起来雅虎只允许OAuth2,任何关于如何进步的帮助将不胜感激。