Twitter Advanced Search



Building standard queries

Search

Standard

Aug 17, 2020 Twitter Advanced Search is a powerful marketing tool for implementing smart social media marketing strategies like perceiving consumer needs, engaging with audiences, researching competitors and turning your findings into content that your target audience will enjoy. From social science to computer science, Twitter data can advance research objectives on topics as diverse as the global conversations happening on Twitter. Apply for the Academic Research product track, now with free access to historical data.

Twitter search

The best way to build a standard query and test if it’s valid and will return matched Tweets is to first try it at twitter.com/search. As you get a satisfactory result set, the URL loaded in the browser will contain the proper query syntax that can be reused in the standard search API endpoint. Here’s an example:

  1. We want to search for Tweets referencing @TwitterDev account. First, we run the search on twitter.com/search
  2. Check and copy the URL loaded. In this case, we got: https://twitter.com/search?q=%40twitterdev
  3. Replace https://twitter.com/search with https://api.twitter.com/1.1/search/tweets.json and you will get: https://api.twitter.com/1.1/search/tweets.json?q=%40twitterdev
  4. Run a Twurl command to execute the search.

Please note that the API requires that the request be authenticated (check Authentication & Authorization documentation for more details on this). Note that the standard search API only serves data from the last week. If you need historical data odler than seven days, check out the premium and enterprise search APIs.

Standard search operators

Twitter Advanced SearchTwitter Advanced Search

The query can have operators that modify its behavior. the available operators are:

OperatorFinds Tweets...
watching nowcontaining both “watching” and “now”. This is the default operator.
“happy hour”containing the exact phrase “happy hour”.
love OR hatecontaining either “love” or “hate” (or both).
beer -rootcontaining “beer” but not “root”.
#haikucontaining the hashtag “haiku”.
from:interiorsent from Twitter account “interior”.
list:NASA/astronauts-in-space-nowsent from a Twitter account in the NASA list astronauts-in-space-now
to:NASAa Tweet authored in reply to Twitter account “NASA”.
@NASAmentioning Twitter account “NASA”.
politics filter:safecontaining “politics” with Tweets marked as potentially sensitive removed.
puppy filter:mediacontaining “puppy” and an image or video.
puppy -filter:retweetscontaining “puppy”, filtering out retweets
puppy filter:native_videocontaining “puppy” and an uploaded video, Amplify video, Periscope, or Vine.
puppy filter:periscopecontaining “puppy” and a Periscope video URL.
puppy filter:vinecontaining “puppy” and a Vine.
puppy filter:imagescontaining “puppy” and links identified as photos, including third parties such as Instagram.
puppy filter:twimgcontaining “puppy” and a pic.twitter.com link representing one or more photos.
hilarious filter:linkscontaining “hilarious” and linking to URL.
puppy url:amazoncontaining “puppy” and a URL with the word “amazon” anywhere within it.
superhero since:2015-12-21containing “superhero” and sent since date “2015-12-21” (year-month-day).
puppy until:2015-12-21containing “puppy” and sent before the date “2015-12-21”.
movie -scary :)containing “movie”, but not “scary”, and with a positive attitude.
flight :(containing “flight” and with a negative attitude.
traffic ?containing “traffic” and asking a question.

Please, make sure to URL encode these queries before making the request. There are several online tools to help you to do that, or you can search at twitter.com/search and copy the encoded URL from the browser’s address bar. The table below shows some example mappings from search queries to URL encoded queries:

Search queryURL encoded query
#haiku #poetry%23haiku+%23poetry
“happy hour” :)%22happy%20hour%22%20%3A%29

Note that the space character can be represented by “%20” or “+” sign.

Additional parameters

There is a set of additional parameters that allows a better control of the search results. The GET search/tweets documentation has detailed information about the usage of the parameters, this section will only give a brief description of their capabilities:

Twitter Advanced Search Not Working

  • Result Type: just like twitter.com/search results, the result_type parameter selects whether the result set will be represented by recent or popular Tweets, or even a mix of both.
  • Geolocalization: the search operator “near” isn’t available in the API, but there is a more precise way to restrict your query by a given location using the geocode parameter specified with the template “latitude,longitude,radius”, for example, “37.781157,-122.398720,1mi”. When conducting geo searches, the search API will first attempt to find Tweets which have lat/long within the queried geocode, and in case of not having success, it will attempt to find Tweets created by users whose profile location can be reverse geocoded into a lat/long within the queried geocode, meaning that is possible to receive Tweets which do not include lat/long information.
  • Language: the lang parameter restricts Tweets to the given language.
  • Iterating in a result set: parameters such count, until, since_id, max_id control iteration through search results, since it could be a large set of Tweets. The Working with Timelines documentation is a rich and illustrative tutorial to learn how to use these parameters to achieve the best efficiency and reliability when processing result sets.