我正在尝试检索过去2个月内的用户推文。但是,LINQ to Twitter将您可以检索的推文数限制为200.有没有办法检索更多?
Twitter api允许分页,如:
http://api.twitter.com/1/statuses/user_timeline.json?id=username8&count=200&page=2
我在LINQ to Twitter库中找不到任何类似的东西。
我尝试了以下操作,但不工作:
var statusTweets = (from tweet in twitterCtx.Status
where tweet.Type == StatusType.User &&
tweet.Count == 200 &&
tweet.ScreenName == "username"
select tweet).Skip(200);
答案 0 :(得分:5)
好的,我觉得现在有点蠢。结果是有一个分页参数。
<强>解决方案强>
for (int i = 0; i < 5; i++)
{
var statusTweets = (from tweet in twitterCtx.Status
where tweet.Type == StatusType.User &&
tweet.Count == 200 &&
tweet.ScreenName == "username" &&
tweet.Page == i
select tweet)
}
答案 1 :(得分:2)
这是一个完整的功能,可以从用户那里获取所有推文
public static List<Status> searchUserTweet(string screenName, int maxPagination)
{
var twitterCtx = new TwitterContext(authorizer);
List<Status> searchResults = new List<Status>();
int maxNumberToFind = 200;
int pagination = 0;
ulong lastId = 0;
int count = 0;
var tweets = (from tweet in twitterCtx.Status
where tweet.Type == StatusType.User &&
tweet.ScreenName == screenName &&
tweet.Count == maxNumberToFind
select tweet).ToList();
if (tweets.Count > 0)
{
lastId = ulong.Parse(tweets.Last().StatusID.ToString());
searchResults.AddRange(tweets);
}
do
{
var id = lastId - 1;
tweets = (from tweet in twitterCtx.Status
where tweet.Type == StatusType.User &&
tweet.ScreenName == screenName &&
tweet.Count == maxNumberToFind &&
tweet.MaxID == id
select tweet).ToList();
searchResults.AddRange(tweets);
lastId = tweets.Min(x => x.StatusID);
pagination++;
count = (pagination > maxPagination) ? 0 : tweets.Count;
} while (count == maxNumberToFind);
return searchResults;
}