Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert a Twitter User ID to a Twitter Username

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.

like image 801
user250181 Avatar asked Oct 30 '25 00:10

user250181


2 Answers

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

like image 165
Matthew Flaschen Avatar answered Nov 01 '25 12:11

Matthew Flaschen


You can get the Twitter username from Twitter ID without using the Twitter API. Calling Twitter API has two issues:

  1. It needs an access token after the release of Twitter API version 1.1.

  2. The number of requests is limited to 150 requests per hour.

like image 28
AccessToken Avatar answered Nov 01 '25 12:11

AccessToken