Twitter currently does not offer permanent links for their users profile pictures. This means that if you do any caching of twitter profile pictures, you stand a good chance of the image being gone by the time you try to display it. We’ve been running into this problem a lot recently at EventVue, but until recently I hadn’t taken the time to try and fix it. Thankfully, someone else solved the problem for me.
Last week Pete Warden wrote about a project that Shannon Whitley started that provides a simple solution for the roaming profile picture. The SPIURL project is a small python script that is designed to run on Google App Engine. It caches the profile URL’s, but checks that the profile image still exists before returning the picture. The end result is a static URL that can be used to retrieve any profile picture from twitter. For example, http://purl.org/net/spiurl/joshfraser returns my profile picture even if I upload a new one to twitter.
It’s a great script as it is, but I made a few modifications of my own. The main thing I added was the ability to specify which size of picture you want — either the 48×48 thumbnail or the original. I also added a content-type header to make it easier to view the picture in a browser. You can download my modified version if you’d like.
Thanks Shannon and Pete for sharing! I hope this helps someone else as much as it helped me.