【问题标题】:Get all tweets with specific hashtag获取所有带有特定主题标签的推文
【发布时间】:2011-03-13 16:17:59
【问题描述】:

我一直在试验 Twitter API,因为我想在一个特殊页面上显示一些推文列表。

在这些列表中有一个列表,其中包含包含特定主题标签的所有推文(例如 #test

但是我找不到如何在 XML 或 JSON(最好是后者)中获取该列表,有人知道如何吗?如果可以在TweetSharp中完成也可以

【问题讨论】:

    标签: twitter tweetsharp


    【解决方案1】:

    您可以简单地获取http://search.twitter.com/search.json?q=%23test 以获取包含#test 的JSON 推文列表,其中%23test#test URL 编码的。

    我对 TweetSharp 不熟悉,但我猜肯定有一个 search 命令可以用来搜索 #test,然后自己将生成的推文转换为 JSON。

    【讨论】:

    【解决方案2】:

    首先使用 github 安装 TweetSharp https://github.com/danielcrenna/tweetsharp

    这是进行搜索的代码

    TwitterService service = new TwitterService();
    var tweets = service.Search("#Test", 100);
    List<TwitterSearchStatus> resultList = new List<TwitterSearchStatus>(tweets.Statuses);    
    

    如果您有超过一页的结果,您可以设置一个循环并调用每一页

     service.Search("#Test", i += 1, 100);
    

    【讨论】:

      【解决方案3】:

      自过去几个月以来,API 似乎发生了变化。这是更新的代码:

      TwitterSearchResult res = twitter.Search(new SearchOptions { Q = "xbox" });
      IEnumerable<TwitterStatus> status = res.Statuses;
      

      【讨论】:

        【解决方案4】:

        您可以使用此 URL 访问您的推文搜索。但是你必须使用 OAuth 协议。

        https://api.twitter.com/1.1/search/tweets.json?q=%40twitterapi

        【讨论】:

          【解决方案5】:

          我也遇到过同样的问题。这是我模糊的解决方案。享受编程。 每当您获得/获取所需数量的推文时,它就会退出该功能。

                  string maxid = "1000000000000"; // dummy value
                  int tweetcount = 0;
          
          
                  if (maxid != null)
                  {
                      var tweets_search = twitterService.Search(new SearchOptions { Q = keyword, Count = Convert.ToInt32(count) });
                      List<TwitterStatus> resultList = new List<TwitterStatus>(tweets_search.Statuses);
                      maxid = resultList.Last().IdStr;
                      foreach (var tweet in tweets_search.Statuses)
                      {
                          try
                          {
                              ResultSearch.Add(new KeyValuePair<String, String>(tweet.Id.ToString(), tweet.Text));
                              tweetcount++;
                          }
                          catch { }
                      }
          
                      while (maxid != null && tweetcount < Convert.ToInt32(count))
                      {
                          maxid = resultList.Last().IdStr;
                          tweets_search = twitterService.Search(new SearchOptions { Q = keyword, Count = Convert.ToInt32(count), MaxId = Convert.ToInt64(maxid) });
                          resultList = new List<TwitterStatus>(tweets_search.Statuses);
                          foreach (var tweet in tweets_search.Statuses)
                          {
                              try
                              {
                                  ResultSearch.Add(new KeyValuePair<String, String>(tweet.Id.ToString(), tweet.Text));
                                  tweetcount++;
                              }
                              catch { }
                          }
          

          }

          【讨论】:

            猜你喜欢
            • 2017-01-05
            • 2013-09-24
            • 2013-06-02
            • 2011-02-12
            • 2017-12-18
            • 2012-12-03
            • 2014-04-15
            • 1970-01-01
            • 2011-08-27
            相关资源
            最近更新 更多