Let's take a look at the Twitter Search API. The basic syntax to use it is bot.getsearch/tweets. There are some parameters which we'll come back to and then your call back function.
If there's an error, we'll print it out. Otherwise, we'll print our data. It's data.statuses. For parameters, we have queue, which is our query. For now, let's look for balloons. It's a good one. We can pass it account. For now, let's just get back five tweets. If we run this, that's a lot of data.
Let's do data.statuses.foreachstatus, print out the text, print the username, the user screen name, and a new line. If we run this again, see what we get back. A bunch of weird tweets about balloons.
The search API returns for relevance and not completeness. It's actually a sampling of tweets from the last seven days. If you want completeness, you should use the stream API, which we'll get into next lesion.
What can you do with the search API? Like we saw, you can search for any word, you can search for two words. This will return tweets with both of those words in it. If you want tweets with this exact phrase, you just put it in quotes, and now we will return tweets with the exact expression.
You can look for tweets containing one of two words. You can look for a word that appears in a tweet without another word. These are all joined together, so you can subtract multiple words.
You can look for emoticons, look for some confusing tweets. You can look for hashtags. You can look for tweets to a user or from a user.
You can start doing some interesting things with media and filters. If you want the word "dance" but you want to filter out any risky tweets you can say, "Filter safe." If you want to picture a video, you can say, "Filter media," and these tweets will include a picture or a video.
If you want to Vine, you can say, "Filter:Vine." That will return vines. You can specifically ask for images and not video. If you want the tweets to have links, you can filter:links and these tweets will have a URL. If you want links from a specific website, you can say your query word URL:Amazon so that Amazon will be in the URL. You can search for questions. You can add a date.
Lastly, there are a couple of additional parameters you can use. One is result_type, and you can pass it either recent or popular. There's also this cool geo code parameter, which takes the format latitude, longitude, and then a radius in miles, which will look for tweets originating from that area. There is also the lang parameter to look for tweets in a language other than English.