#!/usr/bin/env python import os from oauth2client import client, tools from oauth2client.file import Storage SCOPES = 'https://www.googleapis.com/auth/calendar https://mail.google.com/ https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/groups https://www.googleapis.com/auth/admin.directory.user' def get_credentials(): credential_dir =os.getcwd() client_secret_path = os.path.join(credential_dir, 'client_secrets.json') saved_secret_path = os.path.join(credential_dir, 'saved_creds.json') store = Storage(saved_secret_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(client_secret_path, SCOPES, redirect_uri='http://localhost') url = flow.step1_get_authorize_url() flags = tools.argparser.parse_args(args=[]) flags.noauth_local_webserver = True credentials = tools.run_flow(flow, store, flags=flags) return credentials if __name__ == "__main__": get_credentials()