22.Jul.2007
Twitter4R is an open-source library for one of the most popular APIs available, the Twitter REST API. With this library you can create more easily your own twitter clients or mashups, using ruby. I’m going to give a little overview on how to install and use it.
To install Twitter4R, as a gem, simply run:
gem install twitter4rAfter that, you’re ready to start coding.
Let’s start by importing the library with:
require 'twitter'Now we can create our Twitter client
twitter = Twitter::Client.new( :login => 'sdsantos' , :password => 'xxxxxxx' )You can also import you login data from an external YAML file. Just create a file named data.yml for example with the following format:
user:login: sdsantospassword: xxxxxxxand then create the client with it
twitter = Twitter::Client.from_config( 'data.yml' , 'user' )All your and your friends data and messages are available now. For your data you use
twitter.my( :info )and for your friends or followers list use :friends or :followers respectively.
To access the available timelines you can use
timeline = client.timeline_for( :me )But the API isn’t read-only so, to update your personal status use
twitter.status(:post, 'KKTHXBYE from ruby.')As a final example I’ll show you how to add me as a friend:
sergio = Twitter::User.find( 'sdsantos' , 'twitter' )twitter.friend( :add , sergio )You can find more information on this list of articles or just dive into the project’s documentation. You can also follow its releases on their twitter page.
I’m planning on using this library to create mashups for events or other purposes made, for example, with Ruby on Rails. This way you can easily add new friends to your event twitter page and show their messages, as well as report the things happening there. There are many ways to use this library so I would like to hear what are you planning with it.
If you enjoyed this post, consider subscribing to my RSS FeedSérgio Santos | Creative Commons | micro theme by seaofclouds, and powered with Mephisto
2 Comments
The implementation I'm planning is only needed for an event next year. Probably, at that time, you've probably came up with a good solution. I'm already following Twitter4R's twitter profile, so when the solution comes up, I'll noticed it.
Leave a Comment
Follow this post comments with this RSS feed.