Twivatar, a Twitter avatar API

Domain dead; native API available Due to a number of factors, twivatar.org is no longer active (the domain was in fact doomed) – however Twitter stepped up, and now there’s an API to get the avatar directly from them: http://twitter.com/api/users/profile_image/rem – so no longer any need for twivatar anyway.

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 (24×24)
  • normal (48×48 – default)
  • bigger (73×73)
  • 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 ;-)

24 Responses to “Twivatar, a Twitter avatar API”

  1. Wonderful! Thanks a million avatars.

  2. 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.

  3. @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

  4. 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

  5. @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:

  6. 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.

  7. @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/

  8. I can’t thank you enough for this. This solve two major issues in two of my Twitter apps. Way to take the initiative!

  9. 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?

  10. This is perfect. You’re awesome. Thanks so much.

  11. What if the user changes their username?

  12. 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?

  13. this is a fabulous bit of code. any chance of letting us display size in px? awesome!

  14. Hi Guys…
    It seems that this script NO LONGER Works correct… and the Twivatar.org site is down too… Has twitter changed its API already ..I thought this was not happening until June 2010. My Twivatar script is no longer working on my site … Any help or ideas people ?!

    Thanks in advance for your help.

    -JD

  15. @Jamie – sorry for the problems – basically my server got nuked from massive sites no bothering to pull the source code and hosting it themselves. It triggered a DoSS attack causing all my sites to go down. I’ve since been forced to pull the web site until I get a better solution in place – which I think will be a whitelist that I’ll manually moderate.

    In the mean time, you can get the source for the entire application is freely available on github

  16. hey man, first of all kudos for the awesome program, I’m totally hosting it on my server I just want to know how to do it ^^ could you give me some info plz?

  17. Any way we could get a little more detailed information on running this on our own server? I downloaded the source code and uploaded them to my server then changed the herf tag to that directory and still have nothing. Thanks.

  18. I wanted to use this script to create a blogger widget that you would simply add Twitter names to and it would place a grid of the avatars in the widget. I added all of the scripts to my server and pointed it at the address and it showed a broken link picture. Maybe trying to host this yourself is bad and you should put up a tutorial on how to download the script so that it can be self installed.

    Would love a tutorial on this. Thanks for all of the hard work.

  19. Hi Remy,
    It looks like http://twivatar.org is pointing to a GoDaddy holding page :(
    Any chance of twitter hosting this also?

  20. I just found the same as @Philip. Great idea but alas, now I don’t have to decide if this is reliable enough to depend on; clearly it isn’t. (I do understand why; with a revenue stream…)

    -Mike

  21. I downloaded the git code and managed to get it all working (including db and rewrites) and then I discovered that it appears to be somewhat redundant now as you can now do this…

    https://api.twitter.com/1/users/profile_image/

    Are there any benefits to be had using twivatar over this?

    C

  22. Just implemented both methods on a test page and twivatar seems to consistently load faster. I guess this is because the url is stored in the db? Good job Remy.

  23. what’s up with this remy!

  24. I wrote a post about fetching other profile images, They all have open APIs
    http://motyar.blogspot.com/2011/11/open-apis-for-profile-avatar-images.html

Leave a Reply
Not required

CODE: Please escape code and wrap in <pre><code>, doing so will automatically syntax highlight