Created: 2008-11-08 16:11
Updated: 2017-08-26 18:23


A Twitter Search client for Ruby.

Access the Twitter Search API from your Ruby code.


Install the gem.

sudo gem install dancroak-twitter-search -s

Require the gem.

require 'twitter_search'

Set up a TwitterSearch::Client. Name your client (a.k.a. 'user agent') to something meaningful, such as your app's name. This helps Twitter Search answer any questions about your use of the API.

@client = 'politweets'

Request tweets by calling the query method of your client. It takes either a String or a Hash of arguments.

@tweets = @client.query 'twitter search'

The String form uses the default Twitter Search behavior, which in this example finds tweets containing both "twitter" and "search". It is identical to the more verbose, explicit version:

@tweets = @client.query :q => 'twitter search'

Use the Twitter Search API's query operators with the :q key to access a variety of behavior.

Search Operators

The following operator examples find tweets...

Foreign Languages

The Twitter Search API supports foreign languages, accessible via the :lang key. Use the ISO 639-1 codes as the value:

@tweets = @client.query :q => 'programmé', :lang => 'fr'


Alter the number of Tweets returned per page with the :rpp key. Stick with 10, 15, 20, 25, 30, or 50.

@tweets = @client.query :q => 'Boston Celtics', :rpp => '30'


  • Searches are case-insenstive.

  • The "near" operator available in the Twitter Search web interface is not available via the API. You must geocode before making your Twitter Search API call, and use the :geocode key in your request using the pattern lat,lngmi or lat,lngkm:

      @tweets = @client.query :q => 'Pearl Jam', :geocode => '43.4411,-70.9846mi'
  • Searching for a positive attitude :) returns tweets containing the text :), =), :D, and :-)


Written by Dustin Sallings (, forked by Dan Croak (



MIT License, same terms as Ruby.

Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more