4

I'm trying to retrieve a users tweets from the last 2 months. However, LINQ to Twitter limits the amount of tweets you can retrieve to 200. Is there a way to retrieve more?

The Twitter api allows paging, like:

http://api.twitter.com/1/statuses/user_timeline.json?id=username8&count=200&page=2

I couldn't find anything similair in the LINQ to Twitter library.

I tried the following, but it doesn't work:

var statusTweets = (from tweet in twitterCtx.Status
                    where tweet.Type == StatusType.User &&
                    tweet.Count == 200 &&
                    tweet.ScreenName == "username"
                    select tweet).Skip(200);
user1797792
  • 1,169
  • 10
  • 26

2 Answers2

5

Ok, I feel a bit stupid now. Turns out there IS a paging parameter.

Solution

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)
}
user1797792
  • 1,169
  • 10
  • 26
2

Here is a full function to get all the tweets from a user

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;
}
Photonic
  • 1,316
  • 19
  • 31