Esempio n. 1
0
        private IEnumerable <Status> UserStream()
        {
            var request = OAuth.CreateSignedRequest(new Uri("https://userstream.twitter.com/1.1/user.json?delimited=length&with=followings"));

            using (stream = request.GetResponse().GetResponseStream())
                using (var reader = new StreamReader(stream))
                {
                    while (stream.CanRead && !reader.EndOfStream)
                    {
                        var length = 0;
                        var data   = reader.ReadLine();
                        if (int.TryParse(data, out length))
                        {
                            var tweetData = new char[length];
                            reader.Read(tweetData, 0, length);
                            Status tweet = null;
                            try
                            {
                                tweet = JsonConvert.DeserializeObject <Status>(new string(tweetData));
                            }
                            catch (Exception ex)
                            {
                                if (log != null)
                                {
                                    log.WriteLine("{0}: Error: {1}", DateTime.Now, ex.ToString());
                                }
                            }

                            if (tweet != null && tweet.id > 0)
                            {
                                yield return(tweet);
                            }
                        }
                    }
                }
        }