The following code is to get all tweets in a hashtag. if you tried different tags you'll have different result because of the amount of tweets in the last week. the problem is not related to the limit rate time of 15min. I have tried to delay the function. How can I exceed this limit of the first week to all the tweets until I get the first tweet in this hashtag?
private List<Status> statusList= new List<Status>();
private ulong sinceID=1;
private ulong maxID;
public void GetMostRecent200HomeTimeLine()
{
var twitterContext = new TwitterContext(authorizer);
var tweets = from tweet in twitterContext.Status
where tweet.Type == StatusType.Home && tweet.Count == 200
select tweet;
currentTweets = tweets.ToList();
}
public bool TAsyncSearchTag(string tag)
{
var twitterContext = new TwitterContext(authorizer);
Search searchResponse;
try
{
do
{
searchResponse =
(from search in twitterContext.Search
where search.Type == SearchType.Search &&
search.ResultType == ResultType.Mixed &&
search.Query == tag &&
search.Count == 100 &&
search.SinceID == sinceID &&
search.MaxID == maxID
select search)
.FirstOrDefault();
if (searchResponse != null && searchResponse.Statuses.Count > 0)
{
var tweets = from tweet in searchResponse.Statuses
select tweet;
statusList.AddRange(tweets);
maxID = searchResponse.Statuses.Min(x => x.StatusID) - 1;
}
} while (searchResponse.Statuses.Count != 0);
return true;
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return false;
}
}
public List<Status> GetAllTweets(string tag)
{
var twitterContext = new TwitterContext(authorizer);
var searchResponse =
(from search in twitterContext.Search
where search.Type == SearchType.Search &&
search.ResultType == ResultType.Mixed &&
search.Query == tag &&
search.SinceID == sinceID &&
search.Count == 100
select search)
.FirstOrDefault();
var tweets = from tweet
in searchResponse.Statuses
select tweet;
statusList.AddRange(tweets);
maxID = searchResponse.Statuses.Min(x => x.StatusID) - 1;
bool tester = TAsyncSearchTag(tag);
MessageBox.Show("done " + statusList.Count.ToString() + " - " + statusList.Last().StatusID.ToString());
if (statusList != null)
return statusList;
return null;
}