我正在使用tweetsharp库来检索特定标签的tweet
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);
}
我可以从上面的代码片段中检索推文,但它只返回100条推文,似乎推特将其限制为100条推特。这里有人能告诉我如何检索特定标签的所有推文吗。
这是代码。。
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 { }
}
}
}