oauth2.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:google-api-helper 作者: r00tat 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号