views:

243

answers:

1

I'm building an app in Rails that needs to convert a Twitter ID into the Twitter username. This is the code that pulls the ID.

url = 'http://twitter.com/' + params[:username]
buffer = open(url, 'UserAgent' => 'irb').read
@vouched_user_twitter_id = buffer[/\d+(?=\.rss)/]

How do I use that number to pull the username once I no longer have params.

+2  A: 

You can do this with the users/lookup method. This corresponds to the users method of this gem.

Matthew Flaschen
Thanks Matthew - Can you link me to a resource on how to execute that? I'm a noob.
You just have to make an HTTP GET or POST request (in Javascript this would be an Ajax call) to the given url (`http://api.twitter.com/1/users/lookup.xml` or `http://api.twitter.com/1/users/lookup.json`). Of course, you actually need to provide user IDs or screen names you're interested in, so, to poach from that page, you might request `http://api.twitter.com/1/users/lookup.xml?user_id=1401881,1401882` to look up user IDs 1401881 and 1401882 and return the result as XML.
Matt Ball
You have to authenticate first, which is one of the reasons a library is convenient.
Matthew Flaschen