Stream class with parser

Oct 1, 2013 at 7:40 AM
Hi :

I have been using the streamclass but when i get the contet itgive all the content there is a way to show only some field like tweets or username.
My code is the following :

while (true)
        {
            Console.WriteLine("First do nothing");
            Thread.Sleep(90 * 1000);
            try
            {
                using (twitterCtx = new TwitterContext(getAuthorizer()))
                {
                    int counter = 0;
                    string content = "";

                    query = (from strm in twitterCtx.Streaming
                             where strm.Type == StreamingType.Filter &&
                             strm.Locations == "-116.97,32.82,-73,41,-122.75,36.8,-81.376701355,48.5696983337"
                             select strm).StreamingCallback(strm =>
                             {
                                 strm.CloseStream();
                                 return;
                                 if (counter++ > 800 || strm.Status == TwitterErrorStatus.RequestProcessingException)
                                 {

                                     string temp = content;                                         
                                     counter = 0;
                                     strm.CloseStream();
                                               //Here is where you save the content / temp. i used JSON.Net : JObject.Parse ... work very easy

                                     content = "";
                                     return;
                                 }
//I noticed that each time i call strm.content it contains 1 tweet, but every third tweet is garbled for some reason. so I filter:
                                 if (!strm.Content.StartsWith("{\"created") || !strm.Content.EndsWith("\"}"))
                                 {
                                 }
                                 else
                                 {
                                     content += strm.Content;
                                 }
In this strm.Content give everythong there is something to filter for only information, or it in json or there is something to parse just to print some information
Coordinator
Oct 1, 2013 at 4:46 PM
Hi,

The response from the stream arrives as JSON strings. I've seen a couple parsers that other people have written. You can view the Twitter documentation on Streaming Message Types for more info on message format.

@JoeMayo
Oct 1, 2013 at 7:30 PM
Hi :

Thanks for the tip, i have using the .NET Json for parse but the variable strm.content is return me some value but i dont know it json because i set in json editor it show me error the strm.contet show return me this :

"{\"created_at\":\"Tue Oct 01 18:29:35 +0000 2013\",\"id\":385109253453000704,\"id_str\":\"385109253453000704\",\"text\":\"Si @EPN no trae @paolitadurante en si gira favir de dejar de retuitear su itinerario. No pienso ir a verlo.\",\"source\":\"\u003ca href=\\"http:\/\/twitter.com\/download\/android\\" rel=\\"nofollow\\"\u003eTwitter for Android\u003c\/a\u003e\",\"truncated\":false,\"in_reply_to_status_id\":null,\"in_reply_to_status_id_str\":null,\"in_reply_to_user_id\":null,\"in_reply_to_user_id_str\":null,\"in_reply_to_screen_name\":null,\"user\":{\"id\":491899166,\"id_str\":\"491899166\",\"name\":\"J053DU4RD0\",\"screen_name\":\"J053DU4RD0\",\"location\":\"PIRATA en Campeche MX\",\"url\":\"https:\/\/www.facebook.com\\/JOSEDUARDOSIMA\",\"description\":\"Galante con los hombres, caballero con las mujeres, implacable con los ni\u00f1os, tierno con los malvados. WA(+52)9999-704032 Skype\/Instagram\/WeChat\/KiK: J053DU4RD0\",\"protected\":false,\"followers_count\":311,\"friends_count\":312,\"listed_count\":0,\"created_at\":\"Tue Feb 14 04:15:49 +0000 2012\",\"favourites_count\":150,\"utc_offset\":-14400,\"time_zone\":\"Eastern Time (US & Canada)\",\"geo_enabled\":true,\"verified\":false,\"statuses_count\":4190,\"lang\":\"es\",\"contributors_enabled\":false,\"is_translator\":false,\"profile_background_color\":\"C0DEED\",\"profile_background_image_url\":\"http:\/\/a0.twimg.com\/profile_background_images\/378800000047429745\/96e6f05214a0cfe132b6f79922b264be.jpeg\",\"profile_background_image_url_https\":\"https:\/\/si0.twimg.com\/profile_background_images\/378800000047429745\/96e6f05214a0cfe132b6f79922b264be.jpeg\",\"profile_background_tile\":true,\"profile_image_url\":\"http:\/\/a0.twimg.com\/profile_images\/378800000516643863\/24094c07c457de1d108b1832e1db6e5a_normal.jpeg\",\"profile_image_url_https\":\"https:\/\/si0.twimg.com\/profile_images\/378800000516643863\/24094c07c457de1d108b1832e1db6e5a_normal.jpeg\",\"profile_banner_url\":\"https:\/\/pbs.twimg.com\/profile_banners\/491899166\/1379885585\",\"profile_link_color\":\"0084B4\",\"profile_sidebar_border_color\":\"000000\",\"profile_sidebar_fill_color\":\"DDEEF6\",\"profile_text_color\":\"333333\",\"profile_use_background_image\":true,\"default_profile\":false,\"default_profile_image\":false,\"following\":null,\"follow_request_sent\":null,\"notifications\":null},\"geo\":{\"type\":\"Point\",\"coordinates\":[18.5181127,-89.4847508]},\"coordinates\":{\"type\":\"Point\",\"coordinates\":[-89.4847508,18.5181127]},\"place\":{\"id\":\"ea0b11ac2bd8a59a\",\"url\":\"https:\/\/api.twitter.com\/1.1\/geo\/id\/ea0b11ac2bd8a59a.json\",\"place_type\":\"city\",\"name\":\"Champot\u00f3n\",\"full_name\":\"Champot\u00f3n, Campeche\",\"country_code\":\"MX\",\"country\":\"M\u00e9xico\",\"bounding_box\":{\"type\":\"Polygon\",\"coordinates\":[[[-92.32665399999999,17.812147],[-92.32665399999999,21.215460999999998],[-89.414791,21.215460999999998],[-89.414791,17.812147]]]},\"attributes\":{}},\"contributors\":null,\"retweet_count\":0,\"favorite_count\":0,\"entities\":{\"hashtags\":[],\"symbols\":[],\"urls\":[],\"user_mentions\":[{\"screen_name\":\"EPN\",\"name\":\"Enrique Pe\u00f1a Nieto\",\"id\":2897441,\"id_str\":\"2897441\",\"indices\":[3,7]},{\"screen_name\":\"paolitadurante\",\"name\":\"paola durante \",\"id\":264580229,\"id_str\":\"264580229\",\"indices\":[16,31]}]},\"favorited\":false,\"retweeted\":false,\"filter_level\":\"medium\",\"lang\":\"es\"}"

i am not sure that the strm.contet has json structure or i am doing somethign wrong