I am trying to connect to google drive using Oauth on my local machine. I initially tried to follow the quick start steps outlined here https://developers.google.com/drive/v3/web/quickstart/python but it wouldn't connect. I get prompted with the authorisation screen and click allow but I am then redirected to localhost:8080 with an error response message and the log says:
Your browser has been opened to visit:
If your browser is on a different machine then exit and re-run this application with the command-line parameter
--noauth_local_webserver
I have subsequently tried to simply the code to work through it step by step but I keep encountering the same problem that no access code is returned and I can't progress with authentication.
from httplib2 import Http
from oauth2client import file, client, tools
from oauth2client.client import flow_from_clientsecrets
store = file.Storage('credentials.json')
flow = flow_from_clientsecrets('client_secret.json',
scope='https://www.googleapis.com/auth/drive.metadata.readonly',
redirect_uri='http://example.com/auth_return')
print flow
creds = tools.run_flow(flow, store)
print 'access_token: {}'.format(creds.access_token)
service = build('drive', 'v3', http=creds.authorize(Http()))
Any ideas please?
--noauth_local_webserver
, when you run "quickstart.py"? It'spython quickstart.py --noauth_local_webserver
. By this, URL is shown in your console. You can do the authorization by accessing the URL using your browser, and you retrieve the code. Then, you can retrieve refresh token by putting the code to the console. If this was not the solution of your situation, I'm sorry. – Tanaike