A Simple Recipe For Accessing Twitter From Ruby
I wanted to play with accessing Twitter via their REST API and there are several Ruby libraries to do that. I picked one that said it had full support (Twitter4r) and tried it out.
First install the Ruby gem for Twitter4r:
sudo gem install twitter4r
or on Windows:
gem install -–version 1.1.1 json
gem install twitter4r
Then you can access it with a little chunk of code as simple as this:
require('rubygems')
gem('twitter4r', '0.3.0')
require('time')
require('twitter')
client = Twitter::Client.new(:login => 'your Twitter username', :password => 'your Twitter password')
timeline = client.timeline_for(:me)
timeline.each do |status|
puts status.user.screen_name, status.text
end
When I ran that, out popped the last 20 tweets I had done.