多个用户的Twitter API速率限制 [英] Twitter API Rate Limit for Multiple Users

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

问题描述

我正在使用Twitter API编写基于PHP的应用程序.到目前为止,我一直在通过PHP页面上的GET请求使用REST API.但是,随着我的应用程序扩展,我可以很容易地看到它超过了每小时150个请求的限制.原因如下:

I am writing a PHP-based application using the Twitter API. Up until now I've been using the REST API via a GET request on a PHP page. However, as my app scales, I can easily see it going over the 150 requests-per-hour limit. Here's why:

我有几个主题,每个主题都会定期轮询Twitter API以获取有关某个主题的推文.例如,我有:mysite.com/cars、mysite.com/trucks等.用户可以转到任一页面.当他在页面上时,可以通过对我已建立的PHP页面进行AJAX调用来从Twitter获取实时刷新信息. PHP页面确定用户来自哪个类别(汽车,卡车),在Twitter上轮询搜索结果,然后将JSON返回到类别页面.这听起来令人困惑,但是有许多不相关的原因使我需要使用中间PHP页面.

I have categories of topics, each which periodically poll the Twitter API for tweets around a topic. For example, I have: mysite.com/cars, mysite.com/trucks, etc. A user can go to either page. When he is on the page, live, refreshing updates are pulled from Twitter by making an AJAX call to a PHP page I've set up. The PHP page determines which category the user is coming from (cars, trucks), polls Twitter for search results, then returns the JSON to the category page. This sounds confusing, but there are a number of unrelated reasons I need to have the intermediate PHP page.

问题在于,由于PHP页面正在发出请求,因此它将很快耗尽速率限制(想象一下是否有20个类别,而不仅仅是汽车和卡车).我无法使用多个参数进行单个调用,因为它将组合多种类别的推文,并且我无法将它们分开.我可以缓存结果,但是如果这样做,我添加的类别越多,每个API调用之间的间隔就越长.

The problem is that since the PHP page is making the requests, it will eat up the rate limit very quickly (imagine if there were 20 categories instead of just cars and trucks). I can't make a single call with multiple parameters because it would combine multiple categories of tweets and I'd have no way to separate them. I can cache results, but if I did, the more categories I add, the longer each would have to go between API calls.

那么我该如何解决这个问题?我查看了流API,但这仅适用于oAuth用户,并且我不希望我的用户必须登录任何内容.我可以使用PHP页面上的流,然后在每次类别页面轮询PHP页面时仅发出连续请求吗?感谢您的帮助!

So how can I approach this problem? I looked at the streaming API, but it's only for oAuth'd users and I don't want my users to have to log in to anything. Can I use the stream on the PHP page and then just make continuous requests each time the category page polls the PHP page? Thanks for any help!

推荐答案

a)您不必在流式API中使用网站用户的oAuth凭据-只需: 将它们放在dev.twitter.com中的某个位置并对其进行硬编码.您的用户将不知道后台会有任何oAuth.

a) You don't have to use your websites user's oAuth credentials in streaming API - just your's: get them somewhere in dev.twitter.com and hardcode them. Your users won't know there is any oAuth going on backstage.

b)不要使用匿名请求(每小时每个IP 150个),而不要使用oAuth请求(每小时每个oAuth 350个).您不必要求用户唱歌-只需登录几个(1个就可以开始)您的私人Twitter帐户.如果您不喜欢创建Twitter登录功能,则可以在dev.twitter.com中将Twitter帐户的凭据获取到Twitter应用程序.

b) Don't use anonymous requests (150 per IP per hour) use oAuth requests (350 per oAuth per hour). You don't have to ask your users to sing in - just sign in few (1 is sufficient for start) your private twitter accounts. If you don't like creating twitter login functionality, you can get credentials for your twitter account to your twitter application in dev.twitter.com .

c)如@Cheeso所述-缓存!不要让每个页面加载都发出Twitter请求.

c) As @Cheeso mentioned - cache! Don't let every pageload make twitter request.

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

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