Twivatar, a Twitter avatar API
I've built a number of different mini-apps for Twitter, and run in to various API limitations that I've not been happy with (equally, Twitter did add the favourite count and fix the auth issue on favs).
Twitter avatars is one of those annoyances. If you've built an app that caches a Twitter user's avatar, and that user changes their avatar (@joshr is a good example of this), the link breaks, thus breaking your app.
I've spoken to Doug Williams about this (during the Devnest in April) and there's a split argument over at Twitter: some say there should be an API, some say to re-poll Twitter to get the latest avatar.
This weekend I decided that I'd had enough, and decided to hack together a fix myself (affectionately known as a toilet project for those who know me).
I give you: Twivatar (twivatar.org)
Twivatar is a RESTful API that lets you specify a Twitter username and it will return the avatar.
Usage
Usage
<img src="http://twivatar.org/[screen_name]" />
Alternatively you can specify the size image you want from:
- mini (24x24)
- normal (48x48 - default)
- bigger (73x73)
- original
<img src="http://twivatar.org/[screen_name]/[size]" />
I've also got the app whitelisted so there's no worries about it being blocked from Twitter.
All the source code is available on GitHub so go ahead and fork 'n hack if you want to.
You can see the API working in action on the Weird Habit site - yes, it is safe for work
You should follow me on Twitter here I'll tweet about JavaScript, HTML 5 and other such gems (amongst usual tweet-splurges)
Wonderful! Thanks a million avatars.
Have you looked at chinposin.com? they have a URL which will give you the user's latest avatar, but it doesn't provide the resizing that you're offering here.
@Andy - I've come across chinposin.com before (but completely forgot their URL). I did think that their service would provide this, but they don't unless you're following their twitter account (or so far as I can tell).
The app that I'm providing aims to just solve the issue of dead Twitter avatars on the fly.
Cheers - Remy
Hi Remy,
Thanks for twivatar. I've just included it into our app.
Nothing online yet, a beta is promised soon.
Any hint on how this works?
Cheers,
Mic
@Mic - not sure what you mean by “on how this works”. If you include the Twivatar link in the image url, it will mean the avatars won’t break when the image is changed.
You can see it working on a few sites already:
Sorry for the poor wording of my question. Using it in our page was indeed very simple.
I was asking about the way it works behind the scene.
We are building a business app that grabs many services available on the web.
Your service is a new kind, compared to the ones we used so far(JSON, XML, HTML, and in fact is a service on a service) and I'm wondering if this could bring some others integrations ideas.
@Mic - if you're after how it works behind the scenes, feel free to pour over the source code - I put it up on GitHub in the first place for exactly that: http://github.com/remy/twivatar/
I can't thank you enough for this. This solve two major issues in two of my Twitter apps. Way to take the initiative!
I've tried link my Gravatar with my Twitter using your method and it did not work for me, could I be doing something wrong?
This is perfect. You're awesome. Thanks so much.
What if the user changes their username?
I just launched an open source project called RoloPress (www.rolopress.com). Essentially, a contact manager built on WordPress. The contact image in RoloPress is automatically pulled in from Gravatar. I would like to switch to Twitter, by using the Twitter ID assigned to each contact. Since this is an opensource project and is being installed on hundreds of websites I don't want to use twivatar.org, but instead have the users website make the call. I tried implemented with the code from Github, but still only works if I use http://twivatar.org/screen_name. I would like to use http://mywebsite.com/screen_name is this possible?