0

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.

user1274037
  • 395
  • 1
  • 2
  • 10
  • I'm not familiar with this API, but to answer your question about "something": that refers to the query string, where there should be a "code" parameter. That script wants the value of the "code" parameter; that's what "something" is referring to, (some unknown string). – maxcountryman Apr 20 '14 at 15:12
  • what function do you call to receive the code/verifier? Is is specific to each API? – user1274037 Apr 20 '14 at 15:28
  • Try running that script. I think it'll make more sense to you if you see it. – maxcountryman Apr 20 '14 at 15:32
  • thanks for helping me figure this out, but what script should i try running? – user1274037 Apr 20 '14 at 15:45
  • If you are referring to my code, I've done that and it creates a link that includes my client id – user1274037 Apr 20 '14 at 19:29
  • I'm referring to the snippet you linked, i.e. the Github example. The code is in the callback URL, added by the service. – maxcountryman Apr 20 '14 at 23:27
  • thanks maxcountryman I've made some discoveries and it looks like yahoo api works with oauth1service - but now I'm faced with other errors: TypeError: request() got an unexpected keyword argument 'oauth_callback' - i've updated requests and rauth – user1274037 Apr 21 '14 at 05:09
  • Great! You should update your question with the an answer. :) – maxcountryman Apr 22 '14 at 19:44
  • How ironic, if I'd only done what you suggested. I'm revisiting this project now after a lengthy break and realized that majority of my code got deleted. Now I'm stuck at the same step haha – user1274037 Jan 07 '15 at 06:45

0 Answers0