I'm trying to get all tweets(count total tweet number) belong to hashtag. My function is here, how to I use maxID and sinceID for get all tweets. What is the instead of "count"? I dont'know.
if (maxid != null)
{
var searchResponse =
await
(from search in ctx.Search
where search.Type == SearchType.Search &&
search.Query == "#karne" &&
search.Count == Convert.ToInt32(count)
select search)
.SingleOrDefaultAsync();
maxid = Convert.ToString(searchResponse.SearchMetaData.MaxID);
foreach (var tweet in searchResponse.Statuses)
{
try
{
ResultSearch.Add(new KeyValuePair<String, String>(tweet.ID.ToString(), tweet.Text));
tweetcount++;
}
catch {}
}
while (maxid != null && tweetcount < Convert.ToInt32(count))
{
maxid = Convert.ToString(searchResponse.SearchMetaData.MaxID);
searchResponse =
await
(from search in ctx.Search
where search.Type == SearchType.Search &&
search.Query == "#karne" &&
search.Count == Convert.ToInt32(count) &&
search.MaxID == Convert.ToUInt64(maxid)
select search)
.SingleOrDefaultAsync();
foreach (var tweet in searchResponse.Statuses)
{
try
{
ResultSearch.Add(new KeyValuePair<String, String>(tweet.ID.ToString(), tweet.Text));
tweetcount++;
}
catch { }
}
}
}
TweetInvi is even simpler now. All you need to do is:
Here's an example. Remember that
MaxID
is for the current session and prevents re-reading tweets you've already processed in the current session.SinceID
is the oldest tweet you've ever received for this search term and helps you avoid re-reading tweets that you've already processed for this search term during previous sessions. Essentially, you're creating a window whereMaxID
is the newest tweet to get next andSinceID
is the oldest tweet that you don't want to read past. On the first session for a given search term, you would setSinceID
to1
because you don't have an oldest tweet yet. After the session, saveSinceID
so that you don't accidentally re-read tweets.This approach seems like a lot of code, but really gives you more control over the search. e.g. you can examine tweets and determine how many times to query based on the contents of a tweet (like
CreatedAt
). You can wrap the query in atry/catch
block to watch for HTTP 429 when you've exceeded your rate limit or twitter has a problem, allowing you to remember where you were and resume. You could also monitortwitterContext
RateLimit
properties to see if you're getting close and avoid an exception for HTTP 429 ahead of time. Any other technique to blindly read N tweets could force you to waste rate-limit and make your application less scalable.SinceID
for the given search term, if you're saving tweets, to keep from re-reading the same tweets the next time you do a search with that search term.For more info on the mechanics of this, read Working with Timelines in the Twitter docs.
Just wanted to say that with Tweetinvi it would be as simple as :