public void Start() { //TileService.Add<TwitterView>(new TileData //{ // Title = "Peeps", // BackgroundImage = new Uri("pack://siteoforigin:,,,/Resources/Tiles/MB_0005_weather1.png") //}); Task.Factory.StartNew(() => { OAuthTokens tokens = new OAuthTokens(); tokens.AccessToken = "478840940-tgD2Fp5NWXpDPGWyrHTxIjroDODe6F9r8JEkabQ"; tokens.AccessTokenSecret = "Jo4fgjtkYBPTfyuigi3slqOo7lVer7rLXwj6rWs"; tokens.ConsumerKey = "O6MTEfpHhHfhnBr4PuVmlw"; tokens.ConsumerSecret = "lDZgfovK9FEtn8MBsTpGPn8WvuTbGal2yBD4kHLgI"; StreamOptions options = new StreamOptions(); Stream = new TwitterStream(tokens, "v1", options); Stream.StartUserStream(Friends, Stopped, Created, Deleted, DirectMessageCreated, DirectMessageDeleted, Callback); Radio.CurrentTrackChanged += RadioOnCurrentTrackChanged; }) .ContinueWith(task => { if (task.Exception != null) { Logger.Log(task.Exception.ToString(), Category.Exception, Priority.Medium); } }); }
/// <summary> /// Starts UserStream. /// </summary> /// <param name="friendsCallback">A callback called when UserStream is intialized. This can be null.</param> /// <param name="errorCallback">A callback called when UserStream is stopped. This can be null.</param> /// <param name="statusCreatedCallback">A callback when receive a new status. This can be null.</param> /// <param name="statusDeletedCallback">A callback when a status is deleted. This can be null.</param> /// <param name="dmCreatedCallback">A callback when receive a new direct message. This can be null.</param> /// <param name="dmDeletedCallback">A callback when a direct message is deleted. This can be null.</param> /// <param name="eventCallback">A callback when a new event is raised. This can be null.</param> public void StartStreaming(InitUserStreamCallback friendsCallback, StreamStoppedCallback errorCallback, StatusCreatedCallback statusCreatedCallback, StatusDeletedCallback statusDeletedCallback, DirectMessageCreatedCallback dmCreatedCallback, DirectMessageDeletedCallback dmDeletedCallback, EventCallback eventCallback) { var option = new StreamOptions() { Count = 0 }; stream = new TwitterStream(token, UserAgent, option); stream.StartUserStream(friendsCallback, errorCallback, statusCreatedCallback, statusDeletedCallback, dmCreatedCallback, dmDeletedCallback, eventCallback, null); }
/// <summary> /// Starts collecting the twitter data /// </summary> /// <param name="track">Tilde delimeted list of items to track</param> /// <returns></returns> public void StartCollecting(string userAgent, string track, bool includeRawJsonCallback) { #region Prepare Auth Tokens for Twitter OAuthTokens tokens = new OAuthTokens() { ConsumerKey = ConsumerKey, ConsumerSecret = ConsumerSharedSecret, AccessToken = OAuthToken, AccessTokenSecret = OAuthTokenSecret }; #endregion #region Set up items we want to track StreamOptions options = new StreamOptions(); string[] trackItems = track.Split('~'); foreach (string trackItem in trackItems) { options.Track.Add(trackItem); } #endregion stream = new TwitterStream(tokens, userAgent, options); if (includeRawJsonCallback) { stream.StartUserStream(StreamInit, StreamStopped, NewTweet, DeletedTweet, NewDirectMessage, DeletedDirectMessage, OtherEvent, RawJson); } else { stream.StartUserStream(StreamInit, StreamStopped, NewTweet, DeletedTweet, NewDirectMessage, DeletedDirectMessage, OtherEvent, null); } }
public void UserStreamTest() { OAuthTokens tokens = Configuration.GetTokens(); stream = new TwitterStream(tokens); stream.OnStatusReceived += new TwitterStatusReceivedHandler(stream_OnStatus); stream.OnFriendsReceived += new TwitterFriendsReceivedHandler(stream_OnFriendsReceived); stream.OnStatusDeleted += new TwitterStatusDeletedHandler(stream_OnStatusDeleted); stream.StartUserStream(); for (int i = 0; i < 1000; i++) { System.Threading.Thread.Sleep(100); } stream.EndStream(); }
static void Main(string[] args) { Console.BufferWidth = 100; Console.WindowWidth = 100; StreamOptions options = new StreamOptions(); options.Track.Add("#tallycc"); options.Track.Add("tallycc"); options.Track.Add("#tallycodecamp"); options.Track.Add("tallycodecamp"); TwitterStream stream = new TwitterStream( tokens, "Tallahassee CodeCamp2001 Example Application", options); Console.WriteLine("The stream is starting ..."); stream.StartUserStream( StreamInit, StreamStopped, NewTweet, DeletedTweet, NewDirectMessage, DeletedDirectMessage, OtherEvent, RawJson); //optional Console.WriteLine("The stream has started. Press any key to stop."); Console.ReadKey(); Console.WriteLine("Stopping the stream ..."); stream.EndStream(StopReasons.StoppedByRequest, "I'm stopping the stream."); Console.WriteLine("Press any key to exit."); Console.ReadKey(); }
private void toolStripDropDownButton2_Click(object sender, EventArgs e) { toolStripStatusLabel1.Text = "Restarting..."; ts.EndStream(); timeline.Clear(); if (st == StartType.UserStream) { ts.StartUserStream(null, new StreamStoppedCallback((x) => { toolStripStatusLabel1.Text = "Stopped."; }), new StatusCreatedCallback(x => { Add(x); }), null, null, null, new EventCallback(x => { Event(x); }), null); var tt = TwitterTimeline.HomeTimeline(ts.Tokens); try { foreach (var tss in tt.ResponseObject) { timeline.Add(tss); } toolStripStatusLabel1.Text = "Restarted."; } catch { MessageBox.Show(tt.ErrorMessage); } } else if (st == StartType.FilterStream) { string query = ""; if (ts.StreamOptions.Track.Count != 0) { foreach (string ss in ts.StreamOptions.Track) { query += ss + "+AND+"; } query = query.Remove(query.Length - 5, 5); } ts.StartPublicStream(new StreamStoppedCallback((x) => { toolStripStatusLabel1.Text = "Stopped."; }), new StatusCreatedCallback(x => { Add(x); }), null, new EventCallback(x => { Event(x); })); var tt = TwitterSearch.Search(ts.Tokens, query, new SearchOptions() { ResultType = SearchOptionsResultType.Popular }); try { foreach (var tss in tt.ResponseObject) { timeline.Add(new TwitterStatus() { Text = tss.Text, User = new TwitterUser() { ScreenName = tss.FromUserScreenName } }); } toolStripStatusLabel1.Text = "Restarted."; } catch { MessageBox.Show(tt.ErrorMessage); } } else if (st == StartType.Mentions) { ts.StreamOptions.Track.Add("@" + ExtendedOAuthTokens.Tokens.First <ExtendedOAuthTokens>((x) => { return(x.OAuthTokens == ts.Tokens); }).UserName); ts.StartPublicStream(new StreamStoppedCallback((x) => { toolStripStatusLabel1.Text = "Stopped."; }), new StatusCreatedCallback(x => { Add(x); }), null, new EventCallback(x => { Event(x); })); var tt = TwitterTimeline.Mentions(ts.Tokens); try { foreach (var tss in tt.ResponseObject) { timeline.Add(tss); } toolStripStatusLabel1.Text = "Restarted."; } catch { MessageBox.Show(tt.ErrorMessage); } } ShowF(); }
public Column(TwitterStream stream, StartType s, string title) { if (back != null) { listView1.BackgroundImage = back; } InitializeComponent(); listView1.SmallImageList = new ImageList(); ts = stream; if (s == StartType.UserStream) { ts.StartUserStream(null, new StreamStoppedCallback((x) => { toolStripStatusLabel1.Text = "Stopped."; }), new StatusCreatedCallback(x => { Add(x); }), null, null, null, new EventCallback(x => { Event(x); }), null); var tt = TwitterTimeline.HomeTimeline(stream.Tokens); try { foreach (var tss in tt.ResponseObject) { timeline.Add(tss); } } catch { MessageBox.Show(tt.ErrorMessage); } } else if (s == StartType.FilterStream) { string query = ""; if (ts.StreamOptions.Track.Count != 0) { foreach (string ss in ts.StreamOptions.Track) { query += ss + "+AND+"; } query = query.Remove(query.Length - 5, 5); } ts.StartPublicStream(new StreamStoppedCallback((x) => { toolStripStatusLabel1.Text = "Stopped."; }), new StatusCreatedCallback(x => { Add(x); }), null, new EventCallback(x => { Event(x); })); var tt = TwitterSearch.Search(ts.Tokens, query, new SearchOptions() { ResultType = SearchOptionsResultType.Popular }); try { foreach (var tss in tt.ResponseObject) { timeline.Add(new TwitterStatus() { Text = tss.Text, User = new TwitterUser() { ScreenName = tss.FromUserScreenName } }); } } catch { MessageBox.Show(tt.ErrorMessage); } } else if (s == StartType.Mentions) { ts.StreamOptions.Track.Add("@" + ExtendedOAuthTokens.Tokens.First <ExtendedOAuthTokens>((x) => { return(x.OAuthTokens == ts.Tokens); }).UserName); ts.StartPublicStream(new StreamStoppedCallback((x) => { toolStripStatusLabel1.Text = "Stopped."; }), new StatusCreatedCallback(x => { Add(x); }), null, new EventCallback(x => { Event(x); })); var tt = TwitterTimeline.Mentions(stream.Tokens); try { foreach (var tss in tt.ResponseObject) { timeline.Add(tss); } } catch { MessageBox.Show(tt.ErrorMessage); } } st = s; this.Text = title; Columns.Add(this); ShowF(); }