views:

373

answers:

5

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?

Thank you.

A: 

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.

Jeremy Bandini
A: 

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.

Marko
Is there anyway to code it so that the web page visitor is the one fetching the XML?
GingerBreadMane
I don't think so. Because of the "Same origin policy", you cannot fetch the remote content using JS. Perhaps there's a way to do it using Flash and than pass that data to the server, but in that case you're building a system that's a lot more fragile then the one where the server fetches the remote content.
Marko
+1  A: 

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

Jimmy Baker
A: 

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

Pablo Viojo
+3  A: 

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

abraham
I don't think I can get an extra Twitter account to use because the API call for getting the user info (including pic URL) is unauthenticated and counts towards the IP rate limit; not the user rate limit. If you know of an authenticated way to get the pic URL, let me know. Thanks for mentioning twitteravatar.appspot.com. I may ask for permission to use their urls until I can get my IP whitelisted.
GingerBreadMane
You can make them be authenticated. The profile information should still be returned.
abraham