首页 文章

使用python,如何在两个日期之间使用收集推文(使用tweepy)?

提问于
浏览
-1

我如何使用python和tweepy从Twitter收集两个给定日期之间的推文?

有没有办法从......直到...值到搜索API?

注意:我需要能够搜索但不限制特定用户

我正在使用python,我知道代码应该是这样的,但我需要帮助才能使它工作 .

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token_key, access_token_secret)
    api = tweepy.API(auth)

    collection = []
    for tweet in tweepy.Cursor(api.search, ???????).items():
        collection[tweet.id] = tweet._json

2 回答

  • 3

    您必须使用twitter documentation中所述的max_id参数

    tweepy是twitter API的包装器,因此您应该能够使用此参数 .

    根据地理位置,请查看The Search API: Tweets by Place . 它使用相同的搜索API和自定义键 .

  • -1

    经过长时间的调查和稳定后,我很乐意分享我的发现 .

    • 按地理编码搜索:以此格式传递'q'参数中的geocode参数:geocode:"37.781157,-122.398720,500mi", the double quotes are important . 请注意,此api不再支持near附近的参数 . 地理编码提供了更大的灵活性

    • 按时间轴搜索:使用以下格式的参数“since”和“until”:“since:2016-08-01 until:2016-08-02”

    还有一个更重要的注意事项... twitter不允许查询过时的日期 . 我不确定,但我认为他们只给了10-14天 . 所以你不能用这种方式查询上个月的推文 .

    ===================================

    for status in tweepy.Cursor(api.search,
                           q='geocode:"37.781157,-122.398720,1mi" since:2016-08-01 until:2016-08-02 include:retweets',
                           result_type='recent',
                           include_entities=True,
                           monitor_rate_limit=False, 
                           wait_on_rate_limit=False).items(300):
        tweet_id = status.id
        tweet_json = status._json
    

相关问题