1

我现在每天都收到推特提要。我正在使用 tweetinvi Api,我的代码只获取最新的 200 个提要,并且我想要全部。

我的代码是公共函数 getTweets()

    ''Set the credentials
    Dim lObjConsumerKey As String = "[REDACTED]"
    Dim lObjConsumerSecret As String = "[REDACTED]"
    Dim lObjUserAccessToken As String = "[REDACTED]"
    Dim lObjUserAccessSecret As String = "[REDACTED]"
    Auth.SetUserCredentials(lObjConsumerKey, lObjConsumerSecret, lObjUserAccessToken, lObjUserAccessSecret)
    Dim lObjDataTable As New DataTable

    lObjDataTable.Columns.Add("Tweets")
    lObjDataTable.Columns.Add("CreatedAt")

    Dim GetTimelineTweets = Timeline.GetUserTimeline(txtUserName.Text)
    For Each lobjGetgetTweets In GetTimelineTweets

        Dim drNew = lObjDataTable.NewRow

        drNew("Tweets") = lobjGetgetTweets
        drNew("CreatedAt") = lobjGetgetTweets.CreatedAt
        lObjDataTable.Rows.Add(drNew)

    Next

    Return lObjDataTable

End Function
4

2 回答 2

1

根据 GetUserTimeline() 的 Twitter REST API 文档,此行为是设计使然。在count参数的定义中...

指定要尝试和检索的推文数,每个不同请求最多 200 个。

要获取所有推文,请查看Twitter 开发人员网站上的使用时间线。

于 2016-11-29T14:03:37.333 回答
0

我在文档中为您创建了一个示例:https ://github.com/linvi/tweetinvi/wiki/Get-All-User-Tweets

RateLimit.RateLimitTrackerMode = RateLimitTrackerMode.TrackAndAwait;

RateLimit.QueryAwaitingForRateLimit += (sender, args) =>
{
    Console.WriteLine($"Query : {args.Query} is awaiting for rate limits!");
};

long userId = <YOUR_USER_ID>;
var lastTweets = Timeline.GetUserTimeline(userId, 200).ToArray();

var allTweets = new List<ITweet>(lastTweets);
var beforeLast = allTweets;

while (lastTweets.Length > 0 && allTweets.Count <= 3200)
{
    var idOfOldestTweet = lastTweets.Select(x => x.Id).Min();
    Console.WriteLine($"Oldest Tweet Id = {idOfOldestTweet}");

    var numberOfTweetsToRetrieve = allTweets.Count > 3000 ? 3200 - allTweets.Count: 200;
    var timelineRequestParameters = new UserTimelineParameters
    {
        // MaxId ensures that we only get tweets that have been posted 
        // BEFORE the oldest tweet we received
        MaxId = idOfOldestTweet - 1,
        MaximumNumberOfTweetsToRetrieve = numberOfTweetsToRetrieve
    };

    lastTweets = Timeline.GetUserTimeline(userId, timelineRequestParameters).ToArray();
    allTweets.AddRange(lastTweets);
}

// `allTweets` now contains all the tweets that Twitter can return
于 2016-12-15T15:11:37.337 回答