def authorize_application(client_secret_file, scope, credential_cache_file='credentials_cache.json', flow_params=[]):
"""
authorize an application to the requested scope by asking the user in a browser.
:param client_secret_file: json file containing the client secret for an offline application
:param scope: scope(s) to authorize the application for
:param credential_cache_file: if provided or not None, the credenials will be cached in a file.
The user does not need to be reauthenticated
:param flow_params: oauth2 flow parameters
:return OAuth2Credentials object
"""
FLOW = flow_from_clientsecrets(client_secret_file,
scope=scope)
storage = Storage(credential_cache_file)
credentials = storage.get()
if credentials is None or credentials.invalid:
# Run oauth2 flow with default arguments.
level = logging.getLogger().level
credentials = tools.run_flow(FLOW, storage, tools.argparser.parse_args(flow_params))
logging.getLogger().setLevel(level)
return credentials
评论列表
文章目录