【问题标题】:Retrieving all tweets of a particular hashtag using TweetSharp使用 TweetSharp 检索特定主题标签的所有推文
【发布时间】:2015-07-06 17:20:28
【问题描述】:

我正在使用 tweetsharp 库来检索特定主题标签的推文

 var service = new TwitterService(Consumer Key, Consumer Secret);
 service.AuthenticateWith("Access Token", "AccessTokenSecret");
 TwitterSearchResult tweets = service.Search(new SearchOptions { Q = "#Pride",Lang="en"});
 IEnumerable<TwitterStatus> status = tweets.Statuses;
    foreach (var item in status)
            {
                Console.WriteLine(item.User.ScreenName + " " + "Says:" + "\n" + item.Text+"\n"+ "ReTweeted:"+" "+item.RetweetCount);
            }

我可以从上面的代码 sn-p 中检索推文,但它只返回 100 条推文,似乎 twitter 将其限制为 100 条推文。 谁能告诉我如何检索特定主题标签的所有推文。

【问题讨论】:

  • max_id 属性需要 tweet 的 id 并返回 ID 小于(即早于)或等于指定 ID 的结果。在我的场景中 max_id 的合适值是多少? @Habib 有什么想法吗?

标签: c# twitter-bootstrap tweetsharp


【解决方案1】:

这是代码..

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

    }

【讨论】:

    猜你喜欢
    • 2015-08-14
    • 2010-10-31
    • 1970-01-01
    • 2012-11-03
    • 1970-01-01
    • 1970-01-01
    • 2011-03-04
    • 2011-02-12
    • 2017-01-05
    相关资源
    最近更新 更多