1

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:

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.

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.

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!

4

1 回答 1

1

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

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

c)正如@Cheeso 提到的 - 缓存!不要让每个页面加载都发出 twitter 请求。

于 2012-05-09T08:15:31.433 回答