Twitter Search Examples for Twitter Bots
This is a complete list of search operators that you can use with Twitter Bots. The bots will use the Twitter API to find tweets that match your search criteria and perform the action on each of the matching tweets.
|red apples||Tweets that contain both “red” and “apples” anywhere. This is the default operator|
|“merry chrismtas”||Tweets that contain the exact phrase in the same order|
|Apples OR Oranges||Use the Boolean OR operator in capital letters|
|#food||All tweets that contain a particular hashtag|
|@labnol||Tweets that @mention or reference a particular user|
|grapes -apples -oranges||Tweets that contain grapes but not the words apple or oranges|
|from:BarackObama||Tweets written by a specific Twitter user|
|from:BarackObama to:Whitehouse||Twitter from one user that mention another specific user|
|to:BarackObama -filter:links -filter:images||Tweets that do not contain links or images|
|elections list:TIME/time-staff||Search for tweets from users who belong to a particular Twitter list|
|#foodrecipe lang:en||Tweets sent in particular language (en = English). Do not use the lang operator to search tweets in any language.|
|#holiday good OR amazing OR awesome filter:images||Tweets that mention #holiday, described as awesome or amazing, and include photographs|
|tornado filter:media||Show tornado tweets containing images or videos|
|music concert filter:native_video||Show tweets that contain native video (uploaded inside tweet)|
|india filter:news||Shows tweets containing news stores|
|iphone url:amazon||Show tweets that contain the word “iphone” a URL with the word amazon anywhere in the web address.|
|awesome video filter:links||Show tweets that contain the words “awesome” and “video” and include a link (URL)|
|include:replies||The Twitter bot, by default, will ignore tweets that are replies to another tweets|
|include:retweets||The Twitter bot, by default, will skip tweets that are retweets. We suggest that you do not include this filter.|
You can use Twitter bots to only search for geotagged tweets but it takes a few extra steps to construct your search query using geolocation.
Go to Google Maps Lookup and search for a location (let’s say Battery Park, NY).
The info window will display the latitude and longitude information of that place. In the Twitter bot search box, enter geocode:latitude,longitude,radius, where radius units must be specified as either mi (miles) or km (kilometers).
For this example, our geolocation query would be:
geocode:40.7024946,-74.016858,2mi (Search tweets by users located within 2 mile radius of the Battery Park area)
Thousands of tweets are posted every minute and a good number of them could be spam. Twitter offers no option to filter tweets by quality but, while setting up Twitter Bots, you can set up a threshold and any tweet not matching that number will be ignored.
You can specify the Follower / Friend count and tweets from users who have less number of followers / friend that the specified number are ignored.
Similarly, you can specify a minimum number of favorites / retweet count and the bot would only look at tweets that have been retweeted or favorited at least that many number of times.
While the Twitter search API is powerful, there are few limitations that you should be aware of.
- Limit your searches to 10 keywords and operators.
- The near: search operator does not work with Twitter bots. Use the geocode: operator as described above.
- You cannot use before or after search operators to search old tweets by date. These date search operators only work on the Twitter website.
- Twitter search results have a 7 day limit and no tweets will be found for a date older than one week.
- Twitter API may not handle queries that are either too long or contain too many search operators.
- The Twitter 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.
- You can use the lang operator to restrict tweets to the given language but language detection may not be perfect.
- 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.
Google Developer Expert, Google Cloud Champion
Amit Agarwal is a Google Developer Expert in Google Workspace and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India.