def get_credentials():
"""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.
"""
import argparse
flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
flags.noauth_local_webserver = True
store = Storage(gmail_api.CREDENTIAL_FILE)
credentials = store.get()
if not credentials or credentials.invalid:
flow = client.flow_from_clientsecrets(gmail_api.CLIENT_SECRET_FILE, gmail_api.SCOPES)
flow.user_agent = gmail_api.APPLICATION_NAME
if flags:
credentials = tools.run_flow(flow, store, flags)
print 'Storing credentials to ' + gmail_api.CREDENTIAL_FILE
return credentials
评论列表
文章目录