Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A Ruby interface to the Twitter API.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


The Twitter Ruby Gem

A Ruby wrapper for the Twitter REST and Search APIs

What's New in 1.0

This gem has been completely rewritten for version 1.0 thanks to contributions from numerous people. This rewrite breaks compatibility with version 0.9.12 and earlier versions of the gem. Most notably, the Twitter::Base, Twitter:Geo, Twitter::LocalTrends, and Twitter::Trends classes have all been combined in the Twitter::Client class. This gem will display deprecation warnings and forward method calls to the Client class whenever possible. In a handful of cases, method names were changed to improve clarity, consistency, or resolve namespace conflicts.

The Twitter::Search class has remained largely the same, however it no longer accepts a query in its constructor. You can specify a query using the containing method, which is aliased to q.

# Pre-1.0'query')
# Post-1.0'query')

The public APIs defined in version 1.0 of this gem will maintain backwards compatibility until the next major version, following the best practice of Semantic Versioning. You are free to continue using the 0.9 series of the gem, however it will not be maintained, so upgrading to 1.0 is strongly recommended.

For more information, please see the full documentation and examples of the gem's usage below.


Usage Examples

require 'rubygems'
require 'twitter'

# Get a user's location
puts Twitter.user("sferik").location

# Get a user's most recent status update
puts Twitter.user_timeline("sferik").first.text

# Get a status update by id
puts Twitter.status(27558893223).text

# Initialize a Twitter search
search =

# Find the 3 most recent marriage proposals to @justinbieber
search.containing('marry me').to('justinbieber').result_type('recent').per_page(3).each do |r|
  puts "#{r.from_user}: #{r.text}"

# Enough about Justin Bieber

# Let's find a Japanese-language status update tagged #ruby
puts search.hashtag('ruby').language('ja').no_retweets.per_page(1).fetch.results.first.text

# And another
puts search.fetch_next_page.results.first.text

# Calling some methods requires an authenticated client. To get your Twitter OAuth credentials,
# register an app at
Twitter.configure do |config|
  config.consumer_key = YOUR_CONSUMER_KEY
  config.consumer_secret = YOUR_CONSUMER_SECRET
  config.oauth_token = YOUR_OAUTH_TOKEN
  config.oauth_token_secret = YOUR_OAUTH_TOKEN_SECRET

# Initialize your Twitter client
client =

# Post a status update
client.update("I just posted a status update via the Twitter Ruby Gem!")

# Read the most recent status update in your home timeline
puts client.home_timeline.first.text

# Who's your most popular friend?
puts client.friends.sort{|a, b| a.followers_count <=> b.followers_count}

# Who's your most popular follower?
puts client.followers.sort{|a, b| a.followers_count <=> b.followers_count}

# Get your rate limit status
puts client.rate_limit_status.remaining_hits.to_s + " Twitter API request(s) remaining this hour"

Submitting an Issue

We use GitHub to track for bugs and features. Before submitting a bug report or feature request, check to make sure it hasn't already been submitted. You can indicate support for an existing issuse by voting for it. When submitting a bug report, please include a Gist that includes a stack trace and any details that may be necessary to reproduce the bug, including your gem version, Ruby version, and operating system. Ideally, a bug report should include a pull request with failing specs.

Submitting a Pull Request

  1. Fork the project.

  2. Create a topic branch.

  3. Commit your feature or bug fix.

  4. Add specs for your feature or bug fix.

  5. Run bundle exec rake spec:rcov. If your changes are not 100% covered, go back to step 4.

  6. Submit a pull request. Please do not include changes to the gemspec, version, or history file. (If you want to create your own version for some reason, please do so in a separate commit.)


Copyright © 2010 John Nunemaker, Wynn Netherland, Erik Michaels-Ober, Steve Richert. See LICENSE for details.

Something went wrong with that request. Please try again.