Tips to avoid being Rate Limited (避免速率限制的点子)

本文提供了几种策略来帮助开发者减少因速率限制导致的应用程序限制,包括缓存API响应、优先考虑活跃用户、根据搜索结果调整请求频率等。此外还介绍了如何利用流式API和应用级认证来更高效地使用Twitter API。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The tips below are there to help you code defensively and reduce the possibility of being rate limited. Some application features that you may want to provide are simply impossible in light of rate limiting, especially around the freshness of results. If real-time information is an aim of your application, look into  The Streaming APIs  along with  User streams  and Site streams .

Caching

Store API responses in your application or on your site if you expect a lot of use. For example, don't try to call the Twitter API on every page load of your website landing page. Instead, call the API infrequently and load the response into a local cache. When users hit your website load the cached version of the results.

Prioritize active users

If your site keeps track of many Twitter users (for example, fetching their current status or statistics about their Twitter usage), consider only requesting data for users who have recently signed into your site.

Adapt to the search results

If your application monitors a high volume of search terms, query less often for searches that have no results than for those that do. By using a back-off you can keep up to date on queries that are popular but not waste cycles requesting queries that very rarely change. Alternatively, consider using the  The Streaming APIs  and filter on your search terms.

Use application-only auth as a "reserve"

Requests using  Application-only authentication  are evaluated in a separate context to an application's per-user rate limits. For many scenarios, you may want to use this additional rate limit pool as a "reserve" for your typical user-based operations.

Blacklisting

We ask that you honor the rate limit. If you or your application abuses the rate limits we will blacklist it. If you are blacklisted you will be unable to get a response from the Twitter API. If you or your application has been blacklisted and you think there has been an error you can contact the email address on our  Support page . So we can get you back online quickly please include the following information:

  1. If you are using the REST API, make a call to the GET application/rate_limit_status from the account or computer which you believe to be blacklisted.
  2. Explain why you think your application was blacklisted.
  3. Describe in detail how you have fixed the problem that you think caused you to be blacklisted.

    Streaming API

    The Streaming API has rate limiting and access levels that are appropriate for long-lived connections. See the Streaming APIs for more details.

    Leveraging the Streaming API is a great way to free-up your rate limits for more inventive uses of the Twitter API.

    Rate Limiting information for the Streaming API is detailed on Connecting to a streaming endpoint.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值