2
votes

I am writing a web app that needs Twitter user's profile photos only. I retrieve these by parsing the users/show XML unauthenticated API call (http://apiwiki.twitter.com/Twitter-REST-API-Method:-users%C2%A0show):

$twitterXML = simplexml_load_file("http://twitter.com/users/show/".$twitterUsername.".xml");

In my testing I have been hitting the Twitter API rate limit. When I retrieve the user photo URL in the above way is the Twitter API rate limit imposed on the IP address of my server so that anyone who uses my web app contributes to the 150/hour limit? Or is that limit imposed on the IP address of the user who is visiting my web page?

Is there any way to retrieve a user's profile photo without being affected by the rate limit?

5

5 Answers

8
votes

There is a number of ways you can do avoid the rate limiting.

You can use Twavatar and not even hit Twitter directly. http://twitteravatar.appspot.com/

You can create an extra Twitter account to use just as a bot to authenticate with when calling the API giving you an additional 150 hits an hour.

You can get your IP whitelisted in which case you will be able to make 20,000 request an hour. http://twitter.com/help/request_whitelisting

You can have users authenticate with twitter when they visit your site and push the hits to the rate limit off on them. Sign in with Twitter is a good way to achieve this: http://apiwiki.twitter.com/Sign-in-with-Twitter

You can read more about Twitter's rate limiting on their website. http://apiwiki.twitter.com/Rate-limiting

1
votes

It's your server that fetches the XML file, so it's the server IP address that is getting throttled. One solution would be to use some form of caching so you reduce the number of requests that your server is sending.

1
votes

I'd try caching the users's photo for a period of time or persisting the photo on your end so that you don't call twitter each time.

Here's an article on caching with PHP: http://www.developertutorials.com/tutorials/php/php-caching/page1.html

0
votes

I am not extremely familiar with Twitter's API. My first question is whether your users are requesting similar profiles? If there is any similarity between your users' requests for photos you might consider caching profile photos and checking the cache prior to making a request to Twitter.

0
votes

Try asking Twitter to remove the rate limit for your app. If you explain why you need it maybe they can help you.