4

我正在尝试检索过去 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);
4

2 回答 2

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)
}
于 2012-12-20T10:34:06.783 回答
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;
}
于 2015-10-14T09:54:04.350 回答