【问题标题】:How to get 'many' tweets from a user using Twitter API如何使用 Twitter API 从用户那里获取“许多”推文
【发布时间】:2012-02-18 17:01:43
【问题描述】:

有一些问题讨论了如何使用 Twitter API 从用户那里获取推文。 (例如,Twitter API getting any user's all tweetsIs there a way to get all tweets from twitter for a specified user?

我知道我应该使用user_timeline。但我的问题是 Twitter 设置了速率限制,如果我想一次下载 1000 条推文,它会给我一个错误。

在下面的代码中,我向 API 发出了单独的请求,并在每个请求之间休眠了几分钟,但它仍然不起作用。

for p in range(1, 6):
    params['page'] = p
    url = base_url + urllib.urlencode(params)

    r = requests.get(url)
    j = simplejson.loads(r.content)

    for item in j:
       # do something to tweets

time.sleep(180)

有解决办法吗?谢谢。

【问题讨论】:

    标签: python twitter


    【解决方案1】:

    您可以使用例如访问streaming API Tweepy,并使用一个或多个用户 ID 过滤 API statuses 方法。这种方法的优点是流 API 不受速率限制。 This answer 应该可以让您开始使用 Tweepy 和流式 API。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-12
      • 2015-02-21
      • 1970-01-01
      相关资源
      最近更新 更多