Twitter API Image Redirect Sizes

If you need to link in a person’s current avatar in your web app, @raffi added a neat little trick to pull in a couple different sizes. Very handy!

http://api.twitter.com/1/users/profile_image/damon?size=mini
damon

http://api.twitter.com/1/users/profile_image/damon?size=normal
damon

http://api.twitter.com/1/users/profile_image/damon?size=bigger
damon

It does a 302 to the current avatar image file on S3.

Twitter API User Bulk Lookup!

UPDATE: Of course you’ll need to upgrade to do the OAuth dance now to make these calls. Back when this post was written, the HTTP Basic Authentication option was still available to developers.

The Twitter API Team introduced a new method this evening that will be incredibly useful.

You can now batch user lookups by username or ID with one call:

$ curl -u username:password
  "https://api.twitter.com/1/users/lookup.xml
  ?user_id=756264,10145822"

or

$ curl -u username:password 
  "https://api.twitter.com/1/users/lookup.xml
  ?user_name=damon,podlabs"

both return:

<?xml version=”1.0″ encoding=”UTF-8″?>
<users type=”array”>
<user>
<id>756264</id>
<name>Damon Clinkscales</name>
<screen_name>damon</screen_name>
<location>Austin, TX</location>
<description>Father. Husband. Friend. Connector. Helper. Programmer. VitalSource. Podlabs. Austin on Rails.  Cafe Bedouins. SnapTweet. DoesFollow. WhereBeYou.</description>
<profile_image_url>http://a1.twimg.com/profile_images/561257818/mo5_crop_normal.jpg</profile_image_url>
<url>http://blog.damonc.com</url>
<protected>false</protected>
<followers_count>1436</followers_count>
<profile_background_color>ec2727</profile_background_color>
<profile_text_color>051014</profile_text_color>
<profile_link_color>1b3c5f</profile_link_color>
<profile_sidebar_fill_color>AF2C2C</profile_sidebar_fill_color>
<profile_sidebar_border_color>F2E195</profile_sidebar_border_color>
<friends_count>500</friends_count>
<created_at>Wed Feb 07 19:41:27 +0000 2007</created_at>
<favourites_count>138</favourites_count>
<utc_offset>-21600</utc_offset>
<time_zone>Central Time (US &amp; Canada)</time_zone>
<profile_background_image_url>http://s.twimg.com/a/1268246301/images/themes/theme2/bg.gif</profile_background_image_url>
<profile_background_tile>false</profile_background_tile>
<notifications>true</notifications>
<geo_enabled>false</geo_enabled>
<verified>false</verified>
<following>true</following>
<statuses_count>14879</statuses_count>
<lang>en</lang>
<contributors_enabled>false</contributors_enabled>
<status>
<created_at>Thu Mar 11 07:33:18 +0000 2010</created_at>
<id>10312311768</id>
<text>Damon, what are you doing up, you may ask…why, I’m programming the @twitterapi. so far, our diabolical plan w/ the little one is &quot;working&quot;</text>
<source>&lt;a href=&quot;http://www.atebits.com/&quot; rel=&quot;nofollow&quot;&gt;Tweetie&lt;/a&gt;</source>
<truncated>false</truncated>
<in_reply_to_status_id></in_reply_to_status_id>
<in_reply_to_user_id></in_reply_to_user_id>
<favorited>false</favorited>
<in_reply_to_screen_name></in_reply_to_screen_name>
<geo/>
<coordinates/>
<place/>
<contributors/>
</status>
</user>
<user>
<id>10145822</id>
<name>Podlabs</name>
<screen_name>podlabs</screen_name>
<location>Austin, TX</location>
<description>Software ideas, realized.</description>
<profile_image_url>http://a3.twimg.com/profile_images/744436899/PLtwitbig_normal.jpg</profile_image_url>
<url>http://podlabs.com</url>
<protected>false</protected>
<followers_count>13</followers_count>
<profile_background_color>131516</profile_background_color>
<profile_text_color>333333</profile_text_color>
<profile_link_color>009999</profile_link_color>
<profile_sidebar_fill_color>efefef</profile_sidebar_fill_color>
<profile_sidebar_border_color>eeeeee</profile_sidebar_border_color>
<friends_count>3</friends_count>
<created_at>Sun Nov 11 05:57:50 +0000 2007</created_at>
<favourites_count>0</favourites_count>
<utc_offset>-21600</utc_offset>
<time_zone>Central Time (US &amp; Canada)</time_zone>
<profile_background_image_url>http://s.twimg.com/a/1268246301/images/themes/theme14/bg.gif</profile_background_image_url>
<profile_background_tile>true</profile_background_tile>
<notifications></notifications>
<geo_enabled>false</geo_enabled>
<verified>false</verified>
<following></following>
<statuses_count>23</statuses_count>
<lang>en</lang>
<contributors_enabled>false</contributors_enabled>
<status>
<created_at>Wed Mar 10 17:02:41 +0000 2010</created_at>
<id>10279681545</id>
<text>@willie Oh, THAT Death Star. I was thinking about a different floating orb evil empire. I’m glad to hear you think it’s much improved.</text>
<source>&lt;a href=&quot;http://www.atebits.com/&quot; rel=&quot;nofollow&quot;&gt;Tweetie&lt;/a&gt;</source>
<truncated>false</truncated>
<in_reply_to_status_id>10278766590</in_reply_to_status_id>
<in_reply_to_user_id>796105</in_reply_to_user_id>
<favorited>false</favorited>
<in_reply_to_screen_name>willie</in_reply_to_screen_name>
<geo/>
<coordinates/>
<place/>
<contributors/>
</status>
</user>
</users>

Two issues come immediately to mind that this helps out with:

  1. Search API user ids still do not match REST API user ids. So with this, you could pull search results and map the screen name to the REST API user id. The fact that you can do this in bulk will save billions of calls. 🙂
  2. The so-called Social Graph methods, where you can pull a Twitter users’ friend list or following list as a big list of IDs are extremely useful, although they have, to date, only supported IDs in the responses. So with this new call, you could take a social graph of IDs and run them through this bulk lookup to get the screen name. Once you have the screen name, you can create links to the user’s twitter profile, for one thing. This bulk lookup also returns the entire User resource, so at that point you’ve got everything.

Great change. Nice work, Twitter API guys!