2011-03-13 101 views
6

我一直在試驗Twitter API,因爲我想在特殊頁面上顯示一些推文列表。獲取所有帶有特定標籤的推文

在這些名單是包含特定主題標籤的所有微博列表(例如#test

但是我無法找到如何讓XML或JSON(最好是後者),該列表中,沒有人知道如何?這也是好的,如果它能夠在TweetSharp

回答

7

做你可以簡單地取http://search.twitter.com/search.json?q=%23test得到的JSON,其中%23test#test URL編碼含#test鳴叫的列表。

我不熟悉TweetSharp,但我想必須有一個search命令,您可以使用它來搜索#test,然後將生成的tweets自己轉換爲JSON。使用github上 https://github.com/danielcrenna/tweetsharp

這裏是代碼做搜索

+0

太糟糕的服務(search.twitter.com)似乎是降低經常:( 是否有使用api.twitter.com – dtech 2011-03-13 20:31:54

+13

任何替代這不再工作 – 2013-06-17 09:50:16

+1

** IT'S不再工作......不要浪費你的時間** – 2015-07-02 06:03:35

9

首先安裝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); 
+0

循環如何工作超過 一頁? – 2015-12-10 08:50:20

+0

鏈接不起作用 – gonephishing 2017-03-07 14:18:58

4

似乎自從過去幾個月以來API發生了變化。這裏是更新後的代碼:

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

我掙扎着同樣的問題。這是我模糊的解決方案。享受編程。 只要您獲取/獲取所需的推文數量,它就會退出該功能。

 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 { } 
       } 

}

相關問題