def _get_credentials(self, config):
"""Gets valid user credentials from storage.
If nothing has been stored, or if the stored credentials are invalid,
the OAuth2 flow is completed to obtain the new credentials.
Returns:
Credentials, the obtained credential.
"""
store = oauth2client.contrib.dictionary_storage.DictionaryStorage(config, 'oauth2')
credentials = store.get()
if not credentials or credentials.invalid:
print("Ask credentials for " + config['user_id'])
flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
flow.user_agent = APPLICATION_NAME
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('--logging_level', default='ERROR')
parser.add_argument('--noauth_local_webserver', action='store_true',
default=True, help='Do not run a local web server.')
args = parser.parse_args([])
credentials = tools.run_flow(flow, store, args)
config.save()
return credentials
评论列表
文章目录