def get_credentials(self):
"""
Returns 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.
"""
self.home_dir = os.path.expanduser('~')
self.credential_dir = os.path.join(self.home_dir, '.credentials')
if not os.path.exists(self.credential_dir):
logging.debug("Cred directory not found...creating: %s", self.credential_dir)
os.makedirs(self.credential_dir)
self.credential_path = os.path.join(self.credential_dir,
'admin-reports_v1-python-quickstart.json')
self.store = Storage(self.credential_path)
self.credentials = self.store.get()
if not self.credentials or self.credentials.invalid:
if not os.path.isfile(self.client_file):
logging.error("'client_secret.json file is missing. \
Google OAuth must be configured")
sys.exit(1)
self.flow = client.flow_from_clientsecrets(self.client_file, self.scope)
self.flow.user_agent = self.appname
评论列表
文章目录