Marchie,
I donβt see the rest of the stack trace, but I can give you three specific problems with corresponding solutions that will help solve your general problem.
Problem I : The value of redirect_uri not set on the object.
Notice how the request body is specified in get_access_token :
body = urllib.urlencode({ 'grant_type': 'authorization_code', 'client_id': self.client_id, 'client_secret': self.client_secret, 'code': code, 'redirect_uri': self.redirect_uri, 'scope': self.scope })
This depends on the redirect_uri property set on the object for the value that was originally set to generate_authorize_url . So, after recovering the token, calling
token = gdata.gauth.OAuth2Token(...)
you just need to set the redirect URI:
token.redirect_uri = 'http://path/that/you/set'
Problem II : The default value of redirect_uri is incorrect (more specifically, deprecated).
Since you called generate_authorize_url with no arguments, the default value for redirect_uri , which is currently oob , was oob . Since OAuth 2.0 docs , oob not among the supported values ββ(it is deprecated).
If you really use the installed application, you will need to install it
token.redirect_uri = 'urn:ietf:wg:oauth:2.0:oob'
Also, when you call generate_authorize_url to get the initial token, you will need to use this as a keyword parameter
url = token.generate_authorize_url(redirect_uri='urn:ietf:wg:oauth:2.0:oob')
Problem III . You call get_access_token with the wrong value (also the one that was not created in the code snippet).
You should either call it the string value of the code that you receive after authorization, or with a dictionary with 'code' as the key.
This can be done as follows:
import atom.http_core
Post Script . The patch author also posted a blog post about using the patch. (Note that there is a typo in the column when <> redirect_url used instead of redirect_url ).