0

I want to search the tweets of past week using tags.

For example, if I write "Google" in the text box, the code should return every tweet which has the word "Google" in it and has been posted within past 7 days, regardless of who tweeted it.

I am able to get the data of the past hour, but I want to read the data of the past week. here is my code

public static void GetTweet(String query)

    {

         DateTime Pre = DateTime.Now.AddDays(-7);

         SearchOptions options = new SearchOptions(){      
                        SinceDate = Pre,
                PageNumber=pageNumber,

           NumberPerPage =100
        };
        TwitterResponse<TwitterSearchResultCollection> searchResult = TwitterSearch.Search(query,options);
        while (searchResult.Result == RequestResult.Success && pageNumber < 10)
        {
            foreach (var tweet in searchResult.ResponseObject)
            {
                Console.WriteLine(tweet.Text, tweet.CreatedDate);

                pageNumber++;
                searchResult = TwitterSearch.Search(query, options);

            }
        }
    }

2 Answers2

0

The Twitter API is not designed to provide you with data like this, especially when querying for a large dataset like that. Each endpoint has its own limitations. Generally, it's 2000 tweets within the last 2 weeks.

The search API allows you to get up to 1500 tweets (15 pages @ 100 per page).

Ricky Smith
  • 2,379
  • 1
  • 13
  • 29
0

You could do something like this

Dim s As New UserTimelineOptions
s.Count = 3000
s.UseSSL = True
s.APIBaseAddress = "http://api.twitter.com/1/"
s.IncludeRetweets = False
s.UserId = 24769625 'Just a sample account
Dim T As TwitterResponse(Of TwitterStatusCollection) = TwitterTimeline.UserTimeline(tokens, s)
For Each Tweet As TwitterStatus In T.ResponseObject
    Console.WriteLine(Tweet.User.ScreenName & ": " & Tweet.Text)
    'In here just check the created date on the tweet.createddate and look for the time frame
Next
Scott
  • 21,211
  • 8
  • 65
  • 72
Stevel
  • 1