0

Refresh Access Token in Python SDK

Hey, I have the whole OAuth dance wokring, I'm just having trouble refreshing the OAuth token using the Python SDK.

In the following code, my consumer key, secret, etc are all set up correctly. The variable access_token is a legitimate access token. That is, if the token has not expired, and I just comment out the line that refreshes the access token, this bit of code will correctly return the users contacts.

CODEBOX
import yahoo.application
CONSUMER_KEY = '####'
CONSUMER_SECRET = '##'
APPLICATION_ID = '##'
CALLBACK_URL = '##'
oauthapp = yahoo.application.OAuthApplication(CONSUMER_KEY, CONSUMER_SECRET, APPLICATION_ID, CALLBACK_URL)
oauthapp.token = yahoo.oauth.AccessToken.from_string(access_token)
oauthapp.token = oauthapp.refresh_access_token(oauthapp.token)
contacts = oauthapp.getContacts()



The error I get (from App Engine) is:

'oauth_token'
Traceback (most recent call last):
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 513, in __call__
handler.post(*groups)
File "/base/data/home/apps/ritchietestproj/2.345270664321958961/scripteditor.py", line 1249, in post
oauthapp.token = oauthapp.refresh_access_token(oauthapp.token)
File "/base/data/home/apps/ritchietestproj/2.345270664321958961/yahoo/application.py", line 90, in refresh_access_token
self.token = self.client.fetch_access_token(request)
File "/base/data/home/apps/ritchietestproj/2.345270664321958961/yahoo/oauth.py", line 165, in fetch_access_token
return AccessToken.from_string(self.connection.getresponse().read().strip())
File "/base/data/home/apps/ritchietestproj/2.345270664321958961/yahoo/oauth.py", line 130, in from_string
key = params['oauth_token'][0]
KeyError: 'oauth_token'


AND, digging deep into the SDK, for some reason, the problem seems to be with the function "fetch_access_token" where the http request self.connection.getresponse().read().strip() returns the following:

{'oauth_problem': ['parameter_absent'], 'oauth_parameters_absent': ['oauth_consumer_key,oauth_token,oauth_signature_method,oauth_signature,oauth_
timestamp,oauth_nonce']}

I can step through the code and see where all those paramaters are set up.... I'm just lost. How am I using the SDK wrong?

by
2 Replies
  • Ok, can anyone point me to an example of someone using refresh_access_token in the python SDK?
    0
  • I also meet this problem,any one fixed it? Thanks a lot.

    0

Recent Posts

in General Discussion at YDN