【问题标题】:tweetsharp and api streaming?tweetsharp 和 api 流媒体?
【发布时间】:2023-03-17 03:08:01
【问题描述】:

我找不到最近的答案。

据报道,许多旧帖子中的 Tweetsharp 不支持来自 Twitter 用户流 api 的流。但是 github 显示了一个看起来确实支持流的类。

https://github.com/danielcrenna/tweetsharp/blob/cad16546df7c5be6ee528ecfa6171098b662a6ab/src/net40/TweetSharp.Next/Service/TwitterService.Streaming.cs

tweetsharp 现在支持来自 Twitter 的流媒体吗,以前不支持

我正在学习 c#,在我继续花几个小时使用 tweetsharp 之前,我会很欣赏一位经验丰富的程序员的观点。

【问题讨论】:

标签: c# tweetsharp


【解决方案1】:

如果你搜索的只是Twitter's streaming API,你可以实现它而不需要外部库

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

}

【讨论】:

  • 为什么在使用动态时你会obj["user"]["screen_name"] 而不是obj.user.screen_name
  • 我开始考虑这个。谢谢你的例子,我试试看。
  • 不幸的是,事情不再那么简单了。需要 API v1.1,并且仅使用 OAuth。有谁知道在 C# 中哪里可以找到使用 OAuth 的 status/sample.json 阅读器?
猜你喜欢
  • 2013-04-05
  • 1970-01-01
  • 1970-01-01
  • 2016-02-04
  • 2014-07-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多