tweetsharp and api streaming?

偶尔善良 提交于 2019-11-30 07:46:41

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"]);

}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!