无法获取Twitter推文



我现在正在获得Twiiter feed。我正在使用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

根据Twitter REST API Documentaion()()()。在计数参数的定义中...

指定尝试检索的推文数量 根据不同的要求200。

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

我在文档中为您创建了一个示例:https://github.com/linvi/tweetinvi/wiki/wiki/get-alg-alg-all-aser-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

相关内容

  • 没有找到相关文章

最新更新