Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Twitter Undocumented Search Parameters #57

Closed
wants to merge 1 commit into from

1 participant

@whoisjake

There are two parameters that aren't documented in the developer API but are used on their Advanced Search page: http://search.twitter.com/advanced

They are ors and ands; which you can use to query more efficiently. At one time they documented that you could take the queries from search.twitter.com and use them with .json like the API. Not sure if that's the case or not.

I also added the filters:link, which has a side effect of limiting the query to only 7 days.

@whoisjake

Well... skip this, the only important part is the filter:links, the ors and ands are removed and you can do it by saying...

word1 word2 word3 OR word4 OR word5

and accomplish the same thing

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 33 additions and 1 deletion.
  1. +21 −1 lib/twitter/search.rb
  2. +12 −0 test/twitter/search_test.rb
View
22 lib/twitter/search.rb
@@ -66,11 +66,31 @@ def lang(lang)
self
end
- # popular|recent
+ # popular|recent|mixed
def result_type(result_type)
@query[:result_type] = result_type
self
end
+
+ # Filters for tweets with links. Limits query to 7 days.
+ def filter_links
+ @query[:filter] = "links"
+ self
+ end
+
+ # Specifies which words to OR together.
+ def or(word)
+ @query[:ors] ||= []
+ @query[:ors] << word.to_s
+ self
+ end
+
+ # Specifies which words to AND together.
+ def and(word)
+ @query[:ands] ||= []
+ @query[:ands] << word.to_s
+ self
+ end
# Limits the number of results per page
def per_page(num)
View
12 test/twitter/search_test.rb
@@ -40,6 +40,18 @@ class SearchTest < Test::Unit::TestCase
should "should be able to specify not to" do
@search.to('jnunemaker',true).query[:q].should include('-to:jnunemaker')
end
+
+ should "should be able to specify AND query" do
+ @search.and('Foobar').query[:ands].should include('Foobar')
+ end
+
+ should "should be able to specify OR query" do
+ @search.or('Foobar').query[:ors].should include('Foobar')
+ end
+
+ should "should be able to filter by links" do
+ @search.filter_links.query[:filter].should include('link')
+ end
should "should be able to specify not referencing" do
@search.referencing('jnunemaker',true).query[:q].should include('-@jnunemaker')
Something went wrong with that request. Please try again.