public void FilterTest() { OAuthTokens tokens = Configuration.GetTokens(); stream = new TwitterStream(tokens); stream.OnStatusReceived += new TwitterStatusReceivedHandler(stream_OnStatus); FilterStreamOptions options = new FilterStreamOptions(); options.Track.Add("twit_er_izer"); options.Track.Add("twitterizer"); stream.StartFilterStream(options); for (int i = 0; i < 1000; i++) { System.Threading.Thread.Sleep(100); } stream.EndStream(); }
/// <summary> /// Starts the filter stream. Returns public statuses that match one or more filter predicates. /// </summary> /// <param name="options">The options.</param> public void StartFilterStream(FilterStreamOptions options) { if (options == null) { throw new ArgumentNullException("options"); } StringBuilder uriBuilder = new StringBuilder(); if (options.UseSSL) uriBuilder.Append("https://"); else uriBuilder.Append("http://"); uriBuilder.Append("stream.twitter.com/1/statuses/filter.json?"); if (options.Count != 0) { uriBuilder.AppendFormat("count={0}&", options.Count); } if (options.Follow != null && options.Follow.Count > 0) { uriBuilder.AppendFormat("follow={0}&", string.Join(",", options.Follow.ToArray())); } if (options.Track != null && options.Track.Count > 0) { uriBuilder.AppendFormat("track={0}&", string.Join(",", options.Track.ToArray())); } if (options.Locations != null && options.Locations.Count > 0) { uriBuilder.Append("locations="); foreach (Location location in options.Locations) { uriBuilder.AppendFormat("{0},", location.ToString()); } uriBuilder = uriBuilder.Remove(uriBuilder.Length - 1, 1); } StartStream(uriBuilder.ToString()); }