def authorize(outh_file='client_secret.json', outh_creds_store=None, outh_nonlocal=False, service_file=None,
credentials=None, **client_kwargs):
"""Login to Google API using OAuth2 credentials.
This function instantiates :class:`Client` and performs authentication.
:param outh_file: path to outh2 credentials file, or tokens file
:param outh_creds_store: path to directory where tokens should be stored
'global' if you want to store in system-wide location
None if you want to store in current script directory
:param outh_nonlocal: if the authorization should be done in another computer,
this will provide a url which when run will ask for credentials
:param service_file: path to service credentials file
:param credentials: outh2 credentials object
:param no_cache: (http client arg) do not ask http client to use a cache in tmp dir, useful for environments where
filesystem access prohibited
default: False
:returns: :class:`Client` instance.
"""
# @TODO handle exceptions
if not credentials:
if service_file:
with open(service_file) as data_file:
data = jload(data_file)
print('service_email : '+str(data['client_email']))
credentials = ServiceAccountCredentials.from_json_keyfile_name(service_file, SCOPES)
elif outh_file:
credentials = get_outh_credentials(client_secret_file=outh_file, credential_dir=outh_creds_store,
outh_nonlocal=outh_nonlocal)
else:
raise AuthenticationError
rclient = Client(oauth=credentials, **client_kwargs)
return rclient
# @TODO
评论列表
文章目录