Skip to content
March 11, 2010 / Damon Clinkscales

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>
<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_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>
<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_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!

About these ads

4 Comments

Leave a Comment
  1. mikey / May 20 2011 4:26 am

    Man this is great news! The solving of the social graphs issue in particular is totally what I’ve been hoping for. Thanks for posting this.

  2. Mebin / Nov 10 2011 5:52 am

    Thanks big time

Trackbacks

  1. Bookmarks for March 11th from 11:18 to 21:50 — arghh.net
  2. 23時のヘッドライン | CROSS SBM

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: