I am trying to implement twitter oauth in appengine (python) using http://code.google.com/p/oauth-python-twitter .
I use the following code to redirect the user to twitter:
twitter = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET)
request_token = twitter.getRequestToken()
response.set_cookie('request_token', request_token.to_string())
signin_url = twitter.getAuthorizationURL(request_token)
return redirect_to(signin_url)
the user is successfully redirected, but when it returns in my application, I get the following error: HTTP Error 401: Unauthorized
File "/base/data/home/apps/app/controllers/users.py", line 46, in authenticate
access_token = twitter.getAccessToken()
File "/base/data/home/apps/app/lib/python/oauthtwitter.py", line 183, in getAccessToken
token = self._FetchUrl(url, no_cache=True)
......
File "/base/python_dist/lib/python2.5/urllib2.py", line 506, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
The error occurs when I try to get an access token.
request_token = request.cookies['request_token']
token = oauth.OAuthToken.from_string(request_token)
twitter = OAuthApi(app_globals.CONSUMER_KEY, app_globals.CONSUMER_SECRET, token)
access_token = twitter.getAccessToken()
Any idea? Thanks!
source
share