I'm pretty new to connecting to APIs and using OAuth2Service in general. The following has been causing me some issues for a while now and I'm completely stop. My code is as follows:
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: '
When I go to the authorized url page i'm prompted for a code but I don't know how to get the code.
I took the last part from an example on rauth page (https://github.com/litl/rauth/blob/master/examples/github-cli.py) but I don't understand the comment about what i need to change 'something' too.
I've found some examples that use OAuth1Service but I always receive the following error when I try to use 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'
So it seems like yahoo only allows OAuth2, any help on how to progress would be greatly appreciated.