使用沙箱环境和 searchtweets API 了解 Twitter API 速率限制 [英] Understanding Twitter API rate limits using sandbox environment and searchtweets API

查看:48
本文介绍了使用沙箱环境和 searchtweets API 了解 Twitter API 速率限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为许多 Twitter 用户提取 2 年的推文.我正在使用 Python 中的 searchtweets 库和 API 的沙盒版本.

I am trying to pull tweets over a 2 year period for a number of Twitter users. I am using the searchtweets library in Python and the sandbox version of the API.

我正在使用他们的结果流方法:

I am using their Result Stream method:

import searchtweets
rule = gen_rule_payload("from:BBCNews", from_date="2017-01-01",
                            to_date="2017-01-01", results_per_call=100) 
rs = ResultStream(rule_payload=create_rule(i),
                                  max_results=18000,  
                                  max_pages=1,
                                  **premium_search_args) # these are credentials, ommitted for security 
                    tweets = list(rs.stream())

但是,我得到了回报:

HTTP Error code: 429: Request exceeds account’s current package request limits. Please upgrade your package and retry or contact Twitter about enterprise access.

我已经查看了速率限制(https://developer.twitter.com/en/docs/basics/rate-limiting) 并认为我已经正确推断出此类请求的速率限制为每 15 分钟 180,因此将 max_results 限制为 18,000 将阻止对 BBC 的这一请求新闻推文超过 15 分钟窗口的速率限制.每个请求返回 100 个结果,因此 18,000 个结果将是 100 个结果*180 个请求.

I have reviewed the rate limits (https://developer.twitter.com/en/docs/basics/rate-limiting) and thought I had correctly deduced that the rate limit is 180 per 15 minutes for this sort of request, and therefore limiting max_results to 18,000 would prevent this one request for BBC News tweets exceeding the rate limit for a 15-minute window. There are 100 results returned in each request, so 18,000 results would be 100 results*180 requests.

这行不通,所以我想我一定是误会了.如果有人能提供一些进一步的见解,那就太好了.

This is not working, so I think I must have misunderstood. If anyone could provide some further insight that would be great.

推荐答案

您引用的网页说明(顶部第一行):

The web page you’ve cited states (first line at the top):

仅限标准 API 端点,不适用于高级 API

Standard API endpoints only, does not apply to premium APIs

每 15 分钟 180 次请求是指标准(旧版)1.1 搜索 API,仅限于 7 天的非完整索引.在使用沙盒的高级搜索中,如果您正在搜索完整的存档产品,那么当月有 50 个请求,每个请求最多 100 条推文(请参阅您的应用仪表板订阅"部分).在付费层中,您每月有 100 到 2500 个请求,每个请求最多可以覆盖 500 条推文,搜索规则更复杂(沙箱中的 128 个字符超过 1024 个字符)

The 180 requests per 15 minutes refers to the standard (legacy) 1.1 search API, limited to a 7 day non-complete index. In premium search with a sandbox, if you are searching the full archive product, you have 50 requests for the month, with up to 100 Tweets per request (see your app dashboard "subscriptions" section). In the paid tiers, you have up from 100 to 2500 requests per month each of which can cover up to 500 Tweets, with more complex search rules (1024 chars over the 128 chars in sandbox)

查看应用信息中心的订阅"面板,该面板会说明您在当月的请求方面所处的位置.

Check the apps dashboard Subscriptions panel which explains where you’re at in terms of requests for the month.

这篇关于使用沙箱环境和 searchtweets API 了解 Twitter API 速率限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆