这是我的代码:
flow = OAuth2WebServerFlow(client_id='XXXXXX',client_secret='XXXXXXXXX',scope='https://www.googleapis.com/auth/userinfo.email',redirect_uri='https://XXXXXXXX.com/oauth2callback')
log.debug(flow.__dict__)
if not self.request.get("code"):
auth_uri = flow.step1_get_authorize_url()
log.debug("the link " + auth_uri)
self.redirect(auth_uri)
else:
code = self.request.get("code")
log.debug("code=>"+str(code))
credentials = flow.step2_exchange(str(code))
http = httplib2.Http()
http = credentials.authorize(http)
log.info('authorisation completed')
service = build('gmail', 'v2', http=http)
self.render_json(service.__dict__)
毕竟这是代码。我收到如下错误:
Failed to retrieve access token: {
"error" : "invalid_request",
"error_description" : "Invalid parameter value for redirect_uri: Missing scheme: None"
}
追溯错误:
Failed to retrieve access token: {
"error" : "invalid_request",
"error_description" : "Invalid parameter value for redirect_uri: Missing scheme: None"
}
E 2014-07-25 16:42:31.077
invalid_request
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__
return handler.dispatch()
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "/base/data/home/apps/s~syncliologinservice/googlelogin.377497220523277441/handlers/common_handler.py", line 39, in google_login
credentials = flow.step2_exchange(str(code))
File "/base/data/home/apps/s~syncliologinservice/googlelogin.377497220523277441/oauth2client/client.py", line 893, in step2_exchange
raise FlowExchangeError(error_msg)
FlowExchangeError: invalid_request
任何人都可以帮助我。坚持了2天。
答案 0 :(得分:2)
这是因为您缺少重定向URI
在我的例子中
REDIRECT_URI = 'http://localhost:8000/app'
OAUTH2_SCOPE = 'https://www.googleapis.com/auth/drive.readonly'
flow = flow_from_clientsecrets(CLIENTSECRET_LOCATION, OAUTH2_SCOPE)
flow.redirect_uri = REDIRECT_URI
credentials = flow.step2_exchange(authorization_code)