Building standard queries

  1. 951.8k Followers, 0 Following, 176 Posts - See Instagram photos and videos from Twitter (@twitter).
  2. Record: You can record, edit and share videos from the Twitter app (Twitter for iPhone or Twitter for Android OS 4.1 and higher). Import: If you use the Twitter for iPhone or iPad app, you can import videos from your device. Upload: You can upload videos to twitter.com. Go live: Learn how to create a live video right from your Twitter app.
  3. BackTweets enables you to search through an archive of old tweets and find tweets that link back to your site.

This video uses a metaphor of “Twitterville” to illustrate the opportunities to use the Twitter Search feature to find people and information, read news and discover emerging information. It teaches how Twitter Search: Helps businesses listen to customer feedback Creates a real-time news source.

Standard

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

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:

  • 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.
Google uses cookies and data to:Search
  • Deliver and maintain services, like tracking outages and protecting against spam, fraud, and abuse
  • Measure audience engagement and site statistics to understand how our services are used

Twitter Search Has Video

If you agree, we’ll also use cookies and data to:
  • Improve the quality of our services and develop new ones
  • Deliver and measure the effectiveness of ads
  • Show personalized content, depending on your settings
  • Show personalized or generic ads, depending on your settings, on Google and across the web
For non-personalized content and ads, what you see may be influenced by things like the content you’re currently viewing and your location (ad serving is based on general location). Personalized content and ads can be based on those things and your activity like Google searches and videos you watch on YouTube. Personalized content and ads include things like more relevant results and recommendations, a customized YouTube homepage, and ads that are tailored to your interests.

Twitter Search Videos Only

Click “Customize” to review options, including controls to reject the use of cookies for personalization and information about browser-level controls to reject some or all cookies for other uses. You can also visit g.co/privacytools anytime.