tweetsharp and api streaming?
Asked Answered
D

1

1

I can't find a recent answer on this.

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.

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

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

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

Daisydaitzman answered 20/3, 2012 at 0:8 Comment(3)
Good point. Does tweetsharp now supports streaming from Twitter, where it did not beforeDaisydaitzman
This might help you out: TweetSharp - Where did FluentTwitter go?Pulvinate
@Daisydaitzman add it to your question :)Cymbiform
K
5

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

}
Karlynkarma answered 20/3, 2012 at 0:46 Comment(3)
why would you obj["user"]["screen_name"] instead of obj.user.screen_name when using dynamic?Pulvinate
I was starting to consider this. Thanks for the example, ill try it out.Daisydaitzman
Unfortunately, things aren't so simple anymore. v1.1 of the API is required, and uses OAuth only. Does anyone know where to find a status/sample.json reader in C# that uses OAuth?Adonic

© 2022 - 2024 — McMap. All rights reserved.