开发者

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

开发者 https://www.devze.com 2022-12-31 21:09 出处:网络
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.

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:

  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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消