【问题标题】:How can I search the past week's tweets with Twitterizer?如何使用 Twitterizer 搜索过去一周的推文?
【发布时间】:2012-10-11 18:39:08
【问题描述】:

我想使用标签搜索过去一周的推文。

例如,如果我在文本框中输入“Google”,则代码应返回过去 7 天内发布的每条包含“Google”一词的推文,无论是谁发的推文。

我可以获取过去一小时的数据,但我想读取过去一周的数据。这是我的代码

public static void GetTweet(字符串查询)

    {

         DateTime Pre = DateTime.Now.AddDays(-7);

         SearchOptions options = new SearchOptions(){      
                        SinceDate = Pre,
                PageNumber=pageNumber,

           NumberPerPage =100
        };
        TwitterResponse<TwitterSearchResultCollection> searchResult = TwitterSearch.Search(query,options);
        while (searchResult.Result == RequestResult.Success && pageNumber < 10)
        {
            foreach (var tweet in searchResult.ResponseObject)
            {
                Console.WriteLine(tweet.Text, tweet.CreatedDate);

                pageNumber++;
                searchResult = TwitterSearch.Search(query, options);

            }
        }
    }

【问题讨论】:

  • 你能分享一些你所做的代码吗?

标签: asp.net twitter twitterizer


【解决方案1】:

Twitter API 并非旨在为您提供此类数据,尤其是在查询此类大型数据集时。每个端点都有自己的限制。通常,在过去 2 周内有 2000 条推文。

搜索 API 允许您获取多达 1500 条推文(15 页 @ 每页 100 条)。

【讨论】:

    【解决方案2】:

    你可以这样做

    Dim s As New UserTimelineOptions
    s.Count = 3000
    s.UseSSL = True
    s.APIBaseAddress = "http://api.twitter.com/1/"
    s.IncludeRetweets = False
    s.UserId = 24769625 'Just a sample account
    Dim T As TwitterResponse(Of TwitterStatusCollection) = TwitterTimeline.UserTimeline(tokens, s)
    For Each Tweet As TwitterStatus In T.ResponseObject
        Console.WriteLine(Tweet.User.ScreenName & ": " & Tweet.Text)
        'In here just check the created date on the tweet.createddate and look for the time frame
    Next
    

    【讨论】:

      猜你喜欢
      • 2013-02-26
      • 1970-01-01
      • 1970-01-01
      • 2014-11-12
      • 1970-01-01
      • 2014-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多