1

This is my code:

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__)

After all this, code. I am getting an error as below:

Failed to retrieve access token: {
  "error" : "invalid_request",
  "error_description" : "Invalid parameter value for redirect_uri: Missing scheme: None"
}

The traceback error:

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

Can anyone help me out. Stuck for a 2 days on this.

Rikesh
  • 26,156
  • 14
  • 79
  • 87
Vimal
  • 189
  • 1
  • 3
  • 13

1 Answers1

2

This is because you are missing the redirect URI

In my example

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)
PhilippeT
  • 144
  • 8