简体   繁体   English

Twitter Streaming API C#

[英]Twitter Streaming API C#

Hi does anyone know how to use the streaming API for C#? 您有没有人知道如何使用C#的流媒体API? Therefore, whenever there is a new tweet in my account, it will be reflected in my program. 因此,只要我的帐户中有新的推文,它就会反映在我的程序中。

So far the only reliable wrapper I've found for this in .Net land is TweetInvi . 到目前为止,我在.Net上找到的唯一可靠的包装器是TweetInvi Try to ignore that the web site looks like it was designed by a hyperactive 10-year old (thanks MS 'metro' team), the actual library is very well designed and rock solid. 试着忽略这个网站看起来像是由一个活跃的10岁的人设计的(感谢MS'地铁'团队),实际的图书馆设计得很好,坚如磐石。

Assuming of course you have the relevant access tokens (if not see http://dev.twitter.com ), an example of how easy it is to have up and running: 当然假设您有相关的访问令牌(如果没有看到http://dev.twitter.com ),那么启动和运行起来是多么容易的一个例子:

TwitterCredentials.SetCredentials(userToken,userTokenPrivate,apiKey,apiKeyPrivate);
_userStream = Stream.CreateUserStream();
_userStream.TweetCreatedByFriend += (sender,args) => Console.WriteLine(args.Tweet.Text);
_userStream.Start();

This will write the body of tweets to your console output, and it updates even faster than leaving the actual Twitter web site open. 这将把推文的主体写入你的控制台输出,它的更新速度甚至比打开实际的Twitter网站更快。 There are other events exposed for when a tweet is favourited, retweeted, when you have a new follower etc. 当推文被推荐,转发时,当你有新的关注者等时,还会有其他事件暴露出来。

I can vouch for this library as being reliable - I am using it for my CovertTweeter project and have had absolutely no issues with it. 我可以保证这个库是可靠的 - 我将它用于我的CovertTweeter项目并且完全没有问题。 In fact accessing the streaming API through TweetInvi has been even easier than the many brick walls I was left hitting when using REST wrappers like Linq2Twitter and TweetSharp. 事实上,通过TweetInvi访问流API比使用像Linq2Twitter和TweetSharp这样的REST包装器时遇到的许多砖墙更加容易。

Have a look at this post: 看看这篇文章:

Streaming with New .NET HttpClient and HttpCompletionOption.ResponseHeadersRead 使用新的.NET HttpClient和HttpCompletionOption.ResponseHeadersRead进行流式处理

You don't have the complete implementation there but you will get the idea. 你没有完整的实现,但你会明白。

Here is a sample which "Reads data from the Twitter Streaming API and adds it to MSMQ. A second process (included) reads from the queue, parses the json message, and updates a data store." 这是一个示例,“从Twitter Streaming API读取数据并将其添加到MSMQ。第二个进程(包括)从队列中读取,解析json消息,并更新数据存储。”

https://github.com/swhitley/TwitterStreamClient https://github.com/swhitley/TwitterStreamClient

You can change the above problem to generate an event when it updates the data store. 您可以更改上述问题以在更新数据存储时生成事件。 In your program you can subscribe this event to do whatever you want. 在您的程序中,您可以订阅此活动以执行您想要的任何操作。

If you are looking for OAuth based sample then please use "AuthPack" which Provides .NET oAuth for Twitter, Facebook, LinkedIn, and Google: 如果您正在寻找基于OAuth的样本,请使用“AuthPack”,它为Twitter,Facebook,LinkedIn和Google提供.NET oAuth:

https://github.com/swhitley/AuthPack/tree/master/AuthPack https://github.com/swhitley/AuthPack/tree/master/AuthPack

我找到了一个使用流API的好示例代码,这里是Twitterizer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM