获取带有特定主题标签的所有推文

发布于 2024-10-21 20:56:54 字数 235 浏览 2 评论 0原文

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

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

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

I've been experimenting with the Twitter API because I want to display a few lists of tweets on a special page.

Among those lists is a list with all tweets containing a specific hashtag (e.g. #test)

However I cannot find how to get that list in either XML or JSON (preferably the latter), does anyone know how? It is also fine if it can be done in TweetSharp

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

亽野灬性zι浪 2024-10-28 20:56:54

您只需获取 http://search.twitter.com/search.json?q=%23test 即可获取包含 JSON 格式的 #test 的推文列表,其中 < code>%23test 是 #test URL 编码。

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

You can simply fetch http://search.twitter.com/search.json?q=%23test to get a list of tweets containing #test in JSON, where %23test is #test URL encoded.

I'm not familiar with TweetSharp, but I guess there must be a search command that you can use to search for #test, and then transform the resulting tweets into JSON yourself.

剩一世无双 2024-10-28 20:56:54

首先使用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);

First install TweetSharp using github
https://github.com/danielcrenna/tweetsharp

Here is the code to do a search

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

If you have more then one page results you can setup a loop and call each page

 service.Search("#Test", i += 1, 100);
初心未许 2024-10-28 20:56:54

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

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

It seems like there is a change in the API since last few months. Here is the updated code:

TwitterSearchResult res = twitter.Search(new SearchOptions { Q = "xbox" });
IEnumerable<TwitterStatus> status = res.Statuses;
殤城〤 2024-10-28 20:56:54

您可以通过此网址访问您的推文搜索。但你必须使用 OAuth 协议。

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

u access with this url for your tweet searchs. But u have to use OAuth protocols.

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

可遇━不可求 2024-10-28 20:56:54

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

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

}

I struggled with the same problem. Here is my vague solution . Enjoy Programming.
It will get out of the function whenever your required number of tweets are acquired/fetched.

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

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文