【问题标题】:Apply limits on tweets对推文应用限制
【发布时间】:2018-12-17 22:18:34
【问题描述】:

我正在尝试使用 tweepy 在 python 中获取推特数据,我想设置返回的推文数量。 这是我的代码块

class StdOutListener(StreamListener):

    def on_data(self, data):
        print (data)
        return True

    def on_error(self, status):
        print (status)


if __name__ == '__main__':

    #This handles Twitter authetification and the connection to Twitter Streaming API
    l = StdOutListener()
    auth = OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_key, access_secret)
    stream = Stream(auth, l)
    #This line filter Twitter Streams to capture data by the keywords: 'python', 'javascript', 'ruby'
    stream.filter(track=['hello', 'javascript', 'python'])

【问题讨论】:

  • “我要设置返回的推文数量”是什么意思?你想跟踪收到的推文数量吗?
  • 先生,我们可以获得多少条推文。它是基于我们的消费者密钥吗?
  • 基本上我是根据关键字搜索推文。那么有没有我们不能超过的限制..???这个限制是多少?
  • 现在我的代码看起来像,auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) auth.set_access_token(OAUTH_TOKEN, OAUTH_TOKEN_SECRET) api = tweepy.API(auth) search_hashtag = tweepy.Cursor(api.search, q='imran khan',include_entities=True).items(1) 用于 search_hashtag 中的推文: print(json.dumps(tweet._json, indent=1))
  • 如果我不设置限制怎么办? thn 它返回了多少条推文>

标签: python tweepy data-retrieval


【解决方案1】:

Tweepy 提供了方便的 Cursor 接口来遍历不同类型的对象。 Twitter 最多允许提取 3200 条推文。

将par page中的return tweets设置为50:

tweets = api.search(q="place:%s" % place_id, rpp=50)

【讨论】:

    猜你喜欢
    • 2017-07-16
    • 1970-01-01
    • 2021-08-21
    • 1970-01-01
    • 2014-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-09
    相关资源
    最近更新 更多