Return all tweets from my timeline

ぐ巨炮叔叔 提交于 2019-12-05 17:54:32

You would use a combination of Count, MaxID, and SinceID to page through tweets. This sounds strange, but there's a very good reason for this approach, given that the tweet stream is continually updating. I've written a blog post, Working with Timelines with LINQ to Twitter, that points to the Twitter documentation and describes how LINQ to Twitter does this.

// last tweet processed on previous query set
ulong sinceID = 210024053698867204;

ulong maxID;
const int Count = 10;
var statusList = new List<status>();

var userStatusResponse =
    (from tweet in twitterCtx.Status
     where tweet.Type == StatusType.User &&
       tweet.ScreenName == "JoeMayo" &&
       tweet.SinceID == sinceID &&
       tweet.Count == Count
     select tweet)
    .ToList();

statusList.AddRange(userStatusResponse);

// first tweet processed on current query
maxID = userStatusResponse.Min(
    status => ulong.Parse(status.StatusID)) - 1;

do
{
    // now add sinceID and maxID
    userStatusResponse =
        (from tweet in twitterCtx.Status
         where tweet.Type == StatusType.User &&
               tweet.ScreenName == "JoeMayo" &&
               tweet.Count == Count &&
               tweet.SinceID == sinceID &&
               tweet.MaxID == maxID
         select tweet)
        .ToList();

    if (userStatusResponse.Count > 0)
    {
        // first tweet processed on current query
        maxID = userStatusResponse.Min(
            status => ulong.Parse(status.StatusID)) - 1;

        statusList.AddRange(userStatusResponse); 
    }
}
while (userStatusResponse.Count != 0 && statusList.Count < 30);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!