返回我的时间表中的所有推文 [英] Return all tweets from my timeline

查看:120
本文介绍了返回我的时间表中的所有推文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望返回我在时间表上发布的所有推文.

I wish to return ALL the Tweets I have ever posted on my timeline.

我正在使用 Linq To Twitter 库-

var statusTweets =
                from tweet in twitterCtx.Status
                where tweet.Type == StatusType.User
                      && tweet.UserID == MyUserID
                      && tweet.Count == 200
                select tweet;

                statusTweets.ToList().ForEach(
                    tweet => Console.WriteLine(
                    "Name: {0}, Tweet: {1}\n",
                    tweet.User.Name, tweet.Text));

这可以正常工作并带回前200个.但是前200个似乎是我可以检索到的最大值,因为有办法带回1000个?似乎没有next cursor movement选项,就像该库的其他部分一样,可以移至下一页等.

This works fine and brings back the first 200. However the first 200 seems to be the maximum I can retrieve, as there a way to bring back say 1000? There does not seem to be a next cursor movement option like there is in other parts of this library to move onto next pages etc.

推荐答案

您将使用Count,MaxID和SinceID的组合来浏览鸣叫.这听起来很奇怪,但是考虑到tweet流不断更新,采用这种方法的理由很充分.我写了一篇博客文章,

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);

这篇关于返回我的时间表中的所有推文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆