I would like to regenerate a token while having no access to a browser on a server side environment.
I am having difficulties generating a new token when the current token expires during the Oauth2.0 authorization with the Google Drive API.
I have got to a point where my code provides a URL which we would need to GET to get access to a code that needs to be filled back on the server.
I have tried looking around on StackOverflow but have been unsuccessful in finding a solution. Given below is the current state of my code:
def get_latest_token():
store = file.Storage('token.json')
creds = store.get()
token_params = load_json_as_dict('token.json')
if not creds or creds.access_token_expired:
flow = client.flow_from_clientsecrets('credentials.json', 'https://www.googleapis.com/auth/drive')
flags = tools.argparser.parse_args(args=[])
creds = tools.run_flow(flow, store, flags)
bearer_token = "Bearer " + load_json_as_dict('token.json')["access_token"]
return bearer_token
Any help appreciated.