Beispiel #1
0
        public void InitializeTwitter()
        {
            try
            {
                System.Xml.Serialization.XmlSerializer serializer =
                    new System.Xml.Serialization.XmlSerializer(typeof(saveSettings));
                System.IO.FileStream fs = new System.IO.FileStream(
                    @"settings.xml", System.IO.FileMode.Open);
                saveSettings setting = (saveSettings)serializer.Deserialize(fs);
                fs.Close();
                textBox1.Enabled = false;
                //accToken = setting.AccToken;
                token.AccessToken = setting.AccToken;
                //accTokenSec = setting.AccTokenSec;
                token.AccessTokenSecret = setting.AccTokenSec;

                var Stream = new TwitterStream(token, "Feedertter", null);

                StatusCreatedCallback statusCreatedCallback = new StatusCreatedCallback(StatusCreatedCallback);
                RawJsonCallback rawJsonCallback = new RawJsonCallback(RawJsonCallback);

                Stream.StartUserStream(null, null,
                    /*(x) => { label1.Text += x.Text; }*/
                    statusCreatedCallback,
                    null, null, null, null, rawJsonCallback);
            }
            catch
            {
                Process.Start(OAuthUtility.BuildAuthorizationUri(req.Token).ToString());
            }

            //Process.Start(OAuthUtility.BuildAuthorizationUri(req.Token).ToString());
        }
        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();
        }
Beispiel #3
0
        private void StartStreaming()
        {
            OAuthTokens tokens = new OAuthTokens() {
                ConsumerKey = OAuthData.ConsumerKey,
                ConsumerSecret = OAuthData.ConsumerSecret,
                AccessToken = OAuthData.AccessToken,
                AccessTokenSecret = OAuthData.AccessTokenSecret
            };

            StreamOptions options = new StreamOptions();

            twitter_streaming = new TwitterStream(tokens, "Twisland Streaming", options);
            twitter_streaming.StartUserStream(
                Init,
                Stop,
                NewTweet,
                DeletedTweet,
                NewDirectMessage,
                DeletedDirectMessage,
                Other);
        }
Beispiel #4
0
 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();
 }
Beispiel #5
0
        private void textBox1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                OAuthTokenResponse actToken =
                    OAuthUtility.GetAccessToken(consumerKey, consumerSecret, req.Token, textBox1.Text);

                token.AccessToken = actToken.Token;
                token.AccessTokenSecret = actToken.TokenSecret;

                label1.Text += "\n始まったな";

                // start save setting
                saveSettings tokensetting = new saveSettings();
                tokensetting.AccToken = actToken.Token;
                tokensetting.AccTokenSec = actToken.TokenSecret;

                System.Xml.Serialization.XmlSerializer seriarizer =
                    new System.Xml.Serialization.XmlSerializer(typeof(saveSettings));
                System.IO.FileStream fs = new System.IO.FileStream(
                    @"settings.xml", System.IO.FileMode.Create);
                seriarizer.Serialize(fs, tokensetting);
                fs.Close();
                // end save setting

                var Stream = new TwitterStream(token, "Feedertter", null);

                StatusCreatedCallback statusCreatedCallback = new StatusCreatedCallback(StatusCreatedCallback);
                RawJsonCallback rawJsonCallback = new RawJsonCallback(RawJsonCallback);

                Stream.StartUserStream(null, null,
                    /*(x) => { label1.Text += x.Text; }*/
                    statusCreatedCallback,
                    null, null, null, null, rawJsonCallback);

            }
        }
Beispiel #6
0
        public void UserStream(StreamOptions streamOptions, Action<TwitterStream> streamStarted, Action<TwitterIdCollection> friendsCallback, Action<StopReasons> streamErrorCallback,
			Action<TwitterStatus> statusCreatedCallback, Action<TwitterStreamDeletedEvent> statusDeletedCallback,
			Action<TwitterDirectMessage> directMessageCreatedCallback, Action<TwitterStreamDeletedEvent> directMessageDeletedCallback,
			Action<TwitterStreamEvent> eventCallback, Action<string> rawJsonCallback = null)
        {
            var stream = new TwitterStream(OAuthTokens, "MeetCurses", streamOptions);
            new Task(() => {
                stream.StartUserStream((friendsId) => {
                    callbacks.Send(() => friendsCallback(friendsId));
                }, (stopreason) => {
                    callbacks.Send(() => streamErrorCallback(stopreason));
                }, (status) => {
                    callbacks.Send(() => statusCreatedCallback(status));
                }, (status) => {
                    callbacks.Send(() => statusDeletedCallback(status));
                }, (status) => {
                    callbacks.Send(() => directMessageCreatedCallback(status));
                }, (status) => {
                    callbacks.Send(() => directMessageDeletedCallback(status));
                }, (twitterStreamEvent) => {
                    callbacks.Send(() => eventCallback(twitterStreamEvent));
                }, (rawJson) => {
                    callbacks.Send(() => {
                        if (rawJsonCallback != null) {
                            rawJsonCallback(rawJson);
                        }
                    });
                });
                callbacks.Send(() => streamStarted(stream));
            }).Start(TaskScheduler);
        }
        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);
                }
            });
        }
Beispiel #8
0
 /// <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);
 }
        private void StartStreamListener()
        {
            // Starts listening on the Twitter streaming API
            StreamOptions options = new StreamOptions();
            TwitterStream stream = new TwitterStream(Tokens, "StudentRND Twitter Door Lock 2.0 (THE DOOOOOOOOOR)", options);

            stream.StartUserStream(null, new StreamStoppedCallback(delegate(StopReasons ex)
            {
                // Sometimes the Twitter streaming API will kill the stream

                // Log the failure:
                MainForm.Instance.logControl.Add("Twitter stream stopped: " + ex.ToString(), LogEntryType.Error);
                Thread.Sleep(5000);

                // Restart the stream
                StartStreamListener();
            }), new StatusCreatedCallback(ProcessNewStatus), null, null, null, null, null);
        }