使用 TweetSharpAPI 获取所有用户的推文
我实现了一种方法,可以手动抓取搜索 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想要做的是与 Twitter Streaming API 进行交互。此 API 允许您打开与 Twitter 的持久连接,然后 Twitter 将在结果传入时将结果流式传输给您。
(取自 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.
(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:
As well as the "HTTP Server process" column:
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".