def get_authenticated_http_client(args, oauth_scopes):
if args is None:
args = ArgumentParser().parse_args([])
if isinstance(oauth_scopes, str):
# Singleton
oauth_scopes = [oauth_scopes]
flow = oauth2client.client.flow_from_clientsecrets(
CLIENT_SECRETS_FILE,
scope=' '.join(f'https://www.googleapis.com/auth/{scope}' for scope in oauth_scopes),
message=MISSING_CLIENT_SECRETS_MESSAGE,
)
oauth_credentials_file = CONFIGS_DIR / f'credentials-{",".join(oauth_scopes)}.json'
storage = oauth2client.file.Storage(oauth_credentials_file)
credentials = storage.get()
if credentials is None or credentials.invalid:
credentials = oauth2client.tools.run_flow(flow, storage, args)
return credentials.authorize(httplib2.Http())
评论列表
文章目录