简体   繁体   English

Twitter搜索API速率限制Zend

[英]Twitter Search API Rate Limit Zend

We are trying to create a app which allows the user to display the latest twitter news on 20 football teams. 我们正在尝试创建一个应用程序,允许用户显示20个橄榄球队的最新Twitter新闻。 We are using Zend_Service_Twitter_Search with the football team query eg "Arsenal". 我们在足球队查询中使用Zend_Service_Twitter_Search,例如“阿森纳”。

The problem we are having is at any 1 point the website could be taking requests to view all 20 teams news so 20 calls to the API if many users are doing this then the hourly limit will be hit. 我们遇到的问题是,网站可能在任何时候都会请求查看所有20个团队的新闻,因此,如果有许多用户这样做,那么将有20次对API的调用,那么每小时的限制就会达到。

We want the latest news on all 20 teams so we dont want to cache the data longer than 1 mintue. 我们想要所有20个团队的最新消息,因此我们不希望将数据缓存超过1分钟。 Does any one have some advise on this I have been through the documentation but no suggestions there. 有没有人对此提供建议,我已经阅读了文档,但那里没有任何建议。

Cheers 干杯

J Ĵ

This seems to me as more of a backend design issue. 在我看来,这更多地是后端设计问题。 The problems you want to deal with are: 您要解决的问题是:

  1. Provide current data for users of any scale 为各种规模的用户提供当前数据
  2. not exceed api limits, that are unpublished Twitter API limits 不超过api限制,即未发布的Twitter API限制

Seems like the solution is a database/datastore of some kind to persist the data. 好像解决方案是某种数据库/数据存储来持久化数据。
You could make your 20 api calls every minute store the info and then make it available to users as long as you like. 您可以每分钟进行20次api调用,以存储信息,然后根据需要将其提供给用户。

After a brief look at the Twitter API docs it doesn't look like there are any restrictions on storing the data. 简要查看Twitter API文档后,似乎对存储数据没有任何限制。 Although you may want to reconsider how often to use the search API, as the limit in not posted. 尽管您可能想重新考虑使用搜索API的频率,但由于限制没有发布。

I implemented something similar recently. 我最近实现了类似的功能。 The simple answer is work out how many queries you need to make. 简单的答案是计算出您需要进行多少查询。 Let's say 1 for each team so 20 at a time. 假设每个团队1个,一次20个。 Divide 60 seconds (the period of the rate limit) by the (rate limit / number of queries) and simply cache your results in something like memcache for that number of seconds. 将60秒(速率限制的时间段)除以(速率限制/查询数),然后将结果缓存在诸如memcache之类的内容中,保持该秒数。 Then when a user visits the site, pull the results from memcache if they are there, otherwise get them fresh. 然后,当用户访问该网站时,从内存缓存中提取结果(如果有的话),否则请重新获取。 Memcache is great in that it automatically clears out data that expires so you won't go over the rate limit and will always have the freshest data possible (without breaking your rate limit). Memcache的优势在于,它会自动清除过期的数据,因此您不会超出速率限制,并且将始终拥有最新鲜的数据(不会超出速率限制)。

So, if the rate limit is 200 per minute (I know it isn't but it makes the maths easy), you'd cache your results for 60 / (200/20) = 6 seconds. 因此,如果速率限制为每分钟200个(我知道不是,但这使数学很容易),则将结果缓存60 /(200/20)= 6秒。 So at max rate, you would make 10 queries for each of the 20 teams in one minute, so 200 queries a minute, which is bang on the rate limit. 因此,以最大速率,您将在一分钟内对20个团队中的每个团队进行10个查询,因此,每分钟200个查询,这在速率限制上实在是太高了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM