本文介绍了tweetsharp和API流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到这个最近的答案。

I can't find a recent answer on this.

据报道,Tweetsharp在一些老的职位不支持从Twitter的用户流API流。然而github上显示了一个类,它看起来像它支持流。

Tweetsharp reportedly in a number of old posts does not support streaming from the Twitter user stream api. However github shows a class which looks like it does support streaming.

请问tweetsharp现在支持从Twitter,它之前

Does tweetsharp now supports streaming from Twitter, where it did not before

我没有流M学习C#和我会很感激一个有经验的编码器的观点之前,我继续花时间与tweetsharp工作。

I'm learning c# and I'd appreciate the view of an experienced coder before i continue to spend hours working with tweetsharp.

推荐答案

如果你搜索仅,则可以实现它,而不需要外部库

If what you search for is only Twitter's streaming API, you can implement it without a need for an external library

JavaScriptSerializer serializer = new JavaScriptSerializer();

HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("https://stream.twitter.com/1/statuses/sample.json");
webRequest.Credentials = new NetworkCredential("...", "...");
webRequest.Timeout = -1;
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();

StreamReader responseStream = new StreamReader(webResponse.GetResponseStream());
while (true)
{
    var line = responseStream.ReadLine();
    if (String.IsNullOrEmpty(line)) continue;

    dynamic obj = serializer.Deserialize<Dictionary<string, object>>(line);

    if(obj["user"]!=null)
        Console.WriteLine(obj["user"]["screen_name"] + ": " +  obj["text"]);

}

这篇关于tweetsharp和API流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-20 01:46