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.
Yeah, it’s similar with PHP. It’s easy, but it creeps me out that in order to do something with Twitter, people have to give you the keys to the kingdom. I auto-post twitter updates from thecodezone.com and I don’t like to store peoples’ passwords (even though I encrypt ’em), but there’s no other way and they’re way overdue for their new system supporting third parties.
I’d much rather have a system like Facebook where I’d store unique key for the user, and the user can grant me permissions to post and can revoke that permission from within their twitter account.