使用 TweetSharpAPI 获取所有用户的推文

发布于 2024-08-29 13:31:09 字数 534 浏览 3 评论 0原文

我实现了一种方法,可以手动抓取搜索 Twitter 页面并获取不同页面上的推文。 但由于刷新率很快,该方法会触发异常。 因此,我决定使用 TweetSharp API 而不是

 var search = FluentTwitter.CreateRequest()
                           .AuthenticateAs(TWITTER_USERNAME, TWITTER_PASSWORD)
                           .Users()
                           .SearchFor("dumbledore");

var result = search.Request();
var users = result.AsUsers();

网站上的代码。 有谁知道我如何避免提供我的凭据并从所有用户(而不仅仅是我作为朋友的用户)检索?

谢谢!

I have implemented a method which manually scrapes the Search Twitter page and gets the tweets on different pages.
But since there is a fast refresh rate, the method triggers an exception.
Therefore I have decided to use TweetSharp API instead

 var search = FluentTwitter.CreateRequest()
                           .AuthenticateAs(TWITTER_USERNAME, TWITTER_PASSWORD)
                           .Users()
                           .SearchFor("dumbledore");

var result = search.Request();
var users = result.AsUsers();

this code was on the site.
Does anyone know how I can avoid giving my credentials and retrieve from all users and not just the ones I have as friends?

Thanks!

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

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

发布评论

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

评论(1

水中月 2024-09-05 13:31:09

您想要做的是与 Twitter Streaming API 进行交互。此 API 允许您打开与 Twitter 的持久连接,然后 Twitter 将在结果传入时将结果流式传输给您。

Twitter Streaming API 图表

(取自 Twitter Streaming API 页面)

也就是说,TweetSharp 目前不支持 Streaming API。但是,在 .NET 中打开与 Twitter 的连接并在收到响应时对其进行处理并不困难(但是,我建议使用 HttpClient 异步处理此问题,以及使用适当的 JSON 解析库,例如 Json.NET)。

注意图中“流连接过程”中的第三列,特别是中间部分:

接收流式推文,执行处理并存储结果

以及“HTTP 服务器进程”列:

服务器从数据存储中提取处理后的结果并呈现视图。

虽然没有明确提及,但您最好在将推文放入数据存储时保留该推文,然后让另一个进程处理该推文;您可能收到的推文数量如此之大,以至于在您收到推文时执行任何处理都会积压新推文的接收。

对于您的具体情况,您需要访问公共流使用“dumbledore”的 POST 过滤器

What you want to do is interface with the Twitter Streaming API. This API allows you to open a persistent connection with Twitter and Twitter will then stream results to you as they come in.

Twitter Streaming API diagram

(taken from the Twitter Streaming API page)

That said, TweetSharp doesn't currently support the Streaming API. However, it's not difficult to open a connection to Twitter in .NET and process the responses as they're received (however, I'd recommend using the HttpClient class to process this asynchronously, as well as using a proper JSON parsing library, like Json.NET).

Note the third column in the diagram "Streaming connection process", specifically the middle part:

Receives streamed Tweets, performs processing and stores result

As well as the "HTTP Server process" column:

Server pulls processed result from data store and renders view.

While not explicitly mentioned, you are best off just persisting the Tweet as you get it into a data store and then having another process handle the Tweets; the volume of Tweets you might get is so high that performing any processing when you get the Tweet will backlog the receiving of new Tweets.

For your specific case, you'll want to access the Public Streams with a POST filter of "dumbledore".

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