Question

I'm new to Twitter API & trying to get tweets with a specific hashtag in my C# Web application. I was able to authenticate my app & get JSON from Twitter ,here are some questions/issues I have:

API can only return maximum 100 tweets in one call,so how I can check if I've more tweets?

If somebody have code example to convert that(Twitter's) JSON into custom class object,so I can count tweets (I tried but getting errors)?

I used this to generate c# classes from json & getting error while doing following:

JavaScriptSerializer json_serializer = new JavaScriptSerializer();
RootObject routes_list = (RootObject)json_serializer.DeserializeObject(s);
Was it helpful?

Solution

Tweetinvi manages that for you. Here is an example returning 200 results.

var searchParameter = Search.GenerateSearchTweetParameter("#my_tag");

searchParameter.Lang = Language.English;
searchParameter.SearchType = SearchResultType.Popular;
searchParameter.MaximumNumberOfResults = 200;
searchParameter.Since = new DateTime(2013, 12, 1);
// ... There are many different parameters that can be set

var tweets = Search.SearchTweets(searchParameter);
tweets.ForEach(t => Console.WriteLine(t.Text));

// Get number of objects
var nbTweets = tweets.Count();

Hope this helps.

OTHER TIPS

Certainly Tweetinvi as user64 said, is a great API, please for version 2.1 the following does the job. Be aware of set RateLimitTrack mode

        // Set up my credentials in (https://apps.twitter.com)
        Auth.SetUserCredentials(consumer_key, consumer_secret, access_token, access_token_secret);

        // Enable Automatic RateLimit handling
        RateLimit.RateLimitTrackerMode = RateLimitTrackerMode.TrackAndAwait;

        var searchParameter = Search.CreateTweetSearchParameter("#My_Tag");
        searchParameter.Lang = LanguageFilter.Spanish; // or English
        searchParameter.SearchType = SearchResultType.Recent;
        searchParameter.MaximumNumberOfResults = 200; // or any number 
        searchParameter.Since = new DateTime(2013, 12, 1);
        var tweets = Search.SearchTweets(searchParameter); // tweets.Count() has the actual searched tweets
        foreach(var item in tweets)
        {
            // do anything with item and its properties example: item.Text;
        }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top