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 param开发者_运维问答s.
You can do this with the users/lookup method. This corresponds to the users method of this gem.
You can get the Twitter username from Twitter ID without using the Twitter API. Calling Twitter API has two issues:
It needs an access token after the release of Twitter API version 1.1.
The number of requests is limited to 150 requests per hour.
You are looking up user id by RSS, that wrong.
You can inspect user's avatar in tweet list dom with firebug and use "data-user-id" param. That is if you need to get id once for testing purposes. Otherwise, yes - use twitter API described above.
Since March 2013 Twitter has changed their REST 1.0 API, now the procedure is different, read more here.
精彩评论