Question

I'm trying to build a web app that grabs fantasy sports info from Yahoo's API. I know that it requires the use of OAuth in order to speak to the API. It's being created using Flask and will run on Google App Engine.

I've been trying to use python-oauth2 from the folks at SimpleGeo and I keep getting the same exact error when trying to do development work. Here's a snippet of code:

import oauth2 as oauth

consumer = oauth.Consumer(key=settings.OAUTH_CONSUMER_KEY, secret=settings.OAUTH_SHARED_SECRET)
request_token_url = "https://api.login.yahoo.com/oauth/v2/get_request_token"
client = oauth.Client(consumer)

resp, content = client.request(request_token_url, "GET")

Here's the error response I'm getting:

{'status': '401', 'transfer-encoding': 'chunked', 'connection': 'close', 'date': 'Tue, 26 Oct 2010 18:24:16 GMT', 'p3p': 'policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"', 'content-type': 'application/x-www-form-urlencoded', 'www-authenticate': 'OAuth oauth_problem=consumer_key_rejected'}

Now, I have read the documentation available via Yahoo and I'm stumped because (a) it seems all so straightforward and (b) I can't figure out where I'm going wrong. I'm using the consumer key and shared secret provided to me by Yahoo.

This is my first experience with OAuth and any help would be greatly appreciated.

Was it helpful?

Solution

As kanaka pointed out, yahoo's get_access_token call requires the oauth_callback, and simplegeo/oauth2 does not allow you to specify it easily.

Here are a couple of workarounds:

Instead of simplegeo/python-oauth2, take zbowling/python-oauth2 (which is a fork of simplegeo, but with some nice new code, and bugfixes), and then add an extra parameter:

parameters={'oauth_callback': 'http://example.com/callback/'}

to the Client.request call. Like so:

client = Client(consumer)
client.request('https://api.login.yahoo.com/oauth/v2/get_request_token',
               method='GET',
               parameters={'oauth_callback': 'http://example.com/callback/'})

If you insist on working with simplegeo/python-oauth2 then check out the detailed discussion on problems with simplegeo/oauth2 and yahoo oauth, at this page. It has some code fragments that you can use.

OTHER TIPS

I just tried using python-oauth2 (simplegeo's) and got the same problem.

One problem with simplegeo's implementation is that the oauth_callback is easy to provide in the request token request and according to this it is required: http://developer.yahoo.com/oauth/guide/oauth-requesttoken.html

But even when I force that to 'oob' I still have the problem.

You might try yahoo's own python library and see if that helps (and then post back here what you found): http://github.com/yahoo/yos-social-python. I found that from here: http://developer.yahoo.com/social/sdk/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top