Module: Twitter::REST::Search

Included in:
API
Defined in:
lib/twitter/rest/search.rb

Constant Summary

MAX_TWEETS_PER_REQUEST =
100

Instance Method Summary collapse

Instance Method Details

#search(q, options = {}) ⇒ Twitter::SearchResults

Note:

Please note that Twitter's search service and, by extension, the Search API is not meant to be an exhaustive source of Tweets. Not all Tweets will be indexed or made available via the search interface.

Returns tweets that match a specified query.

Options Hash (options):

  • :geocode (String)

    Returns tweets by users located within a given radius of the given latitude/longitude. The location is preferentially taking from the Geotagging API, but will fall back to their Twitter profile. The parameter value is specified by "latitude,longitude,radius", where radius units must be specified as either "mi" (miles) or "km" (kilometers). Note that you cannot use the near operator via the API to geocode arbitrary locations; however you can use this geocode parameter to search near geocodes directly.

  • :lang (String)

    Restricts tweets to the given language, given by an ISO 639-1 code.

  • :locale (String)

    Specify the language of the query you are sending (only ja is currently effective). This is intended for language-specific clients and the default should work in the majority of cases.

  • :result_type (String)

    Specifies what type of search results you would prefer to receive. Options are "mixed", "recent", and "popular". The current default is "mixed."

  • :count (Integer)

    The number of tweets to return per page, up to a maximum of 100.

  • :until (String)

    Optional. Returns tweets generated before the given date. Date should be formatted as YYYY-MM-DD.

  • :since_id (Integer)

    Returns results with an ID greater than (that is, more recent than) the specified ID. There are limits to the number of Tweets which can be accessed through the API. If the limit of Tweets has occured since the since_id, the since_id will be forced to the oldest ID available.

  • :max_id (Integer)

    Returns results with an ID less than (that is, older than) or equal to the specified ID.

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



28
29
30
31
32
# File 'lib/twitter/rest/search.rb', line 28

def search(q, options = {})
  options[:count] ||= MAX_TWEETS_PER_REQUEST
  request = Twitter::REST::Request.new(self, :get, '/1.1/search/tweets.json', options.merge(:q => q))
  Twitter::SearchResults.new(request)
end