Twitter Query based search

Query based search

The search endpoint has a number of options for finding tweets. You can search by a given word, sentence as well as hashtags and user mentions.

Example on a simple search

Below is shown an example for a simple search - that is searching for a single hashtag. The example will make a search for tweets containing the #umbraco hashtag, and then print the text/message of each tweet to the console.

// Make the request to the API
TwitterSearchTweetsResponse response = service.Search.GetTweets("#umbraco");

// Iterate through the tweets
foreach (TwitterStatusMessage tweet in response.Body.Statuses) {

    Console.WriteLine(tweet.Text);
    Console.WriteLine();
                
}

By the default, Twitter will respond with the 15 most recent tweets matching your search query.

To get even more tweets per request, you can set a limit to a higher value - like:

// Make the request to the API
TwitterSearchTweetsResponse response = service.Search.GetTweets("#umbraco", 100);

The maximum limit for this method seems to be 100. Nothing will go wrong if you specify a higher limit - the API will just not respond with more than 100 tweets per page.

Query Operators

The query operators supported by the Twitter API can be combined, and therefore a bit complex. So rather than trying the same here, you can read more about query operators at the The Search API page on dev.twitter.com.