2

I am using tweetsharp library to retrieve tweets of a particular hashtag

 var service = new TwitterService(Consumer Key, Consumer Secret);
 service.AuthenticateWith("Access Token", "AccessTokenSecret");
 TwitterSearchResult tweets = service.Search(new SearchOptions { Q = "#Pride",Lang="en"});
 IEnumerable<TwitterStatus> status = tweets.Statuses;
    foreach (var item in status)
            {
                Console.WriteLine(item.User.ScreenName + " " + "Says:" + "\n" + item.Text+"\n"+ "ReTweeted:"+" "+item.RetweetCount);
            }

I am able to retrieve tweets from above code snippet but it only returns 100 tweets, seems like twitter restrict it to 100 tweets. Can anybody here tell me how to retrieve all the tweets of a particular hashtag.

Farrukh Ahmed
  • 473
  • 4
  • 11
  • 26
  • http://stackoverflow.com/questions/20682182/tweetsharp-c-sharp-api-search-only-returns-first-100-tweets – Habib Jul 06 '15 at 17:21
  • max_id attribute requires id of tweet and return results with an ID less than (that is, older than) or equal to the specified ID. What will be the suitable value for max_id in my scenario? @Habib any idea? – Farrukh Ahmed Jul 06 '15 at 17:26

1 Answers1

1

Here is the code..

     string maxid = "1000000000000"; // dummy value
    int tweetcount = 0;


    if (maxid != null)
    {
        var tweets_search = twitterService.Search(new SearchOptions { Q = keyword, Count = Convert.ToInt32(count) });
        List<TwitterStatus> resultList = new List<TwitterStatus>(tweets_search.Statuses);
        maxid = resultList.Last().IdStr;
        foreach (var tweet in tweets_search.Statuses)
        {
            try
            {
                ResultSearch.Add(new KeyValuePair<String, String>(tweet.Id.ToString(), tweet.Text));
                tweetcount++;
            }
            catch { }
        }

        while (maxid != null && tweetcount < Convert.ToInt32(count))
        {
            maxid = resultList.Last().IdStr;
            tweets_search = twitterService.Search(new SearchOptions { Q = keyword, Count = Convert.ToInt32(count), MaxId = Convert.ToInt64(maxid) });
            resultList = new List<TwitterStatus>(tweets_search.Statuses);
            foreach (var tweet in tweets_search.Statuses)
            {
                try
                {
                    ResultSearch.Add(new KeyValuePair<String, String>(tweet.Id.ToString(), tweet.Text));
                    tweetcount++;
                }
                catch { }
            }
        }

    }