twitter_auth.py 文件源码

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

项目:twitterresearch 作者: trifle 项目源码 文件源码
def authorize(filepath=None):
    """
    Create an authorization object for use with the requests
    library. Takes the path to a yaml-encoded file containing twitter API keys.

    :param filepath:
    :type filepath: str
    :returns: OAuth1Session
    """
    # Try to find the file if no path was given
    # find_keyfile returns a generator and .next() gives the first match
    try:
        filepath = filepath or next(find_keyfile())
    except StopIteration:
        raise Exception("No Keyfile found - please place keys.yaml with your tokens in the project directory or pass a custom filepath to the authorize() function")
    # Load credentials from keyfile
    with open(filepath, 'r') as f:
        keys = yaml.load(f)

    # Create authentication object
    auth_object = OAuth1Session(client_key=keys["client_key"],
                                client_secret=keys["client_secret"],
                                resource_owner_key=keys["resource_owner_key"],
                                resource_owner_secret=keys["resource_owner_secret"])
    return auth_object
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号