示例#1
0
        public TwitterSearchStream(TwitterProtocolManager protocolManager,
                                   GroupChatModel chat, string keyword,
                                   OAuthTokens tokens, WebProxy proxy)
        {
            if (protocolManager == null) {
                throw new ArgumentNullException("protocolManager");
            }
            if (chat == null) {
                throw new ArgumentNullException("chat");
            }
            if (keyword == null) {
                throw new ArgumentNullException("keyword");
            }
            if (tokens == null) {
                throw new ArgumentNullException("tokens");
            }

            ProtocolManager = protocolManager;
            Session = protocolManager.Session;
            Chat = chat;

            var options = new StreamOptions();
            options.Track.Add(keyword);

            Stream = new TwitterStream(tokens, null, options);
            Stream.Proxy = proxy;
            Stream.StartPublicStream(OnStreamStopped, OnStatusCreated, OnStatusDeleted, OnEvent);

            MessageRateLimiter = new RateLimiter(5, TimeSpan.FromSeconds(5));
        }
        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);
                }
            });
        }
示例#3
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 override bool OnStart()
        {
            #region base
            // Définissez le nombre maximal de connexions simultanées 
            ServicePointManager.DefaultConnectionLimit = 12;
            #endregion

            tokens = new OAuthTokens()
            {
                ConsumerKey = "REMOVED",
                ConsumerSecret = "REMOVED",
                AccessToken = "REMOVED",
                AccessTokenSecret = "REMOVED"
            };

            options = new StreamOptions();
            options.Track.Add("#travel");
            options.Track.Add("travel");
            options.Track.Add("#plane");
            options.Track.Add("plane");

            stream = new TwitterStream(
                tokens,
                "Demo Jerome CHRIST Twitter Stream Big Data",
                options);

            // Retrieve the storage account ConnectionString from the settings
            storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));

            // Create a blob client
            blobClient = storageAccount.CreateCloudBlobClient();

            // Retrieve a reference to a container. 
            container = blobClient.GetContainerReference("socialtravel");


            //// Create or overwrite the blob
            //using (var fileStream = System.IO.File.OpenRead(@"path\myfile"))
            //{
            //    blockBlob.UploadFromStream(fileStream);
            //}

            #region base
            // Pour plus d'informations sur la gestion des modifications de configuration
            // consultez la rubrique MSDN à l'adresse http://go.microsoft.com/fwlink/?LinkId=166357.

            return base.OnStart();
            #endregion

        }
示例#5
0
        public void StartCaptureStreaming(string searchkey)
        {
            StreamOptions options = new StreamOptions();
            options.Track.Add(searchkey);

            _stream = new TwitterStream(tokens, "TwitterSky", options);

            _stream.StartPublicStream(
                StreamStopped,
                NewTweet,
                DeletedTweet,
                OtherEvent
            );
        }
        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();
        }
        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();
        }
        public void StartCaptureStreaming(SearchParameters parameters)
        {
            StreamOptions options = new StreamOptions();
            options.Track.Add(parameters.SearchKey);
            this._stopSearch = false;

            TwitterStream stream = new TwitterStream(tokens, "RTSearch (Dev)", options);

            IAsyncResult result = stream.StartPublicStream(
                StreamStopped,
                NewTweet,
                DeletedTweet,
                OtherEvent
            );

            while (!this._stopSearch)
            {

            }

            stream.EndStream(StopReasons.StoppedByRequest, "Stop by user");
        }
示例#9
0
        /// <summary>
        /// Twitterストリームを初期化
        /// </summary>
        /// <param name="output">ログ出力用Delegate</param>
        private Twitter(logOutput output = null)
        {
            LogOutput = output;

            if (
                string.IsNullOrWhiteSpace(Properties.Settings.Default.consumerKey) ||
                string.IsNullOrWhiteSpace(Properties.Settings.Default.consumerSecret) ||
                string.IsNullOrWhiteSpace(Properties.Settings.Default.accessToken) ||
                string.IsNullOrWhiteSpace(Properties.Settings.Default.accessTokenSecret)
                )
            {
                OAuthForm f = new OAuthForm();
                if (f.ShowDialog() == System.Windows.Forms.DialogResult.Abort)
                {
                    System.Windows.Forms.Application.Exit();
                    Environment.Exit(0);
                }
                Properties.Settings.Default.Reload();
            }

            token = new OAuthTokens
            {
                ConsumerKey = Properties.Settings.Default.consumerKey,
                ConsumerSecret = Properties.Settings.Default.consumerSecret,
                AccessToken = Properties.Settings.Default.accessToken,
                AccessTokenSecret = Properties.Settings.Default.accessTokenSecret
            };

            ustream = new TwitterStream(token, "labMonitor", null);

            var k = Properties.Settings.Default.Kamatte;
            var opt = new StreamOptions();
            if (k != null)
            {
                opt.Follow = k.GetTargetIdArray();
                opt.Track = k.GetTargetNameArray();
                pstream = new TwitterStream(token, "labMonitorPublic", opt);
            }
        }
示例#10
0
        public void PublicStream(StreamOptions streamOptions, Action<TwitterStream> streamStarted,
			Action<StopReasons> streamErrorCallback,
			Action<TwitterStatus> statusCreatedCallback, Action<TwitterStreamDeletedEvent> statusDeletedCallback,
			Action<TwitterStreamEvent> eventCallback, Action<string> rawJsonCallback = null)
        {
            var stream = new TwitterStream(OAuthTokens, "MeetCurses", streamOptions);
            new Task(() => {
                stream.StartPublicStream((stopreason) => {
                    callbacks.Send(() => streamErrorCallback(stopreason));
                }, (status) => {
                    callbacks.Send(() => statusCreatedCallback(status));
                }, (status) => {
                    callbacks.Send(() => statusDeletedCallback(status));
                }, (twitterStreamEvent) => {
                    callbacks.Send(() => eventCallback(twitterStreamEvent));
                }, (rawJson) => {
                    callbacks.Send(() => {
                        if (rawJsonCallback != null) {
                            rawJsonCallback(rawJson);
                        }
                    });
                });
            }).Start(TaskScheduler);
        }
示例#11
0
        public static void startStream(StreamOptions options)
        {
            Console.BufferWidth = 100;
            Console.WindowWidth = 100;

            TwitterStream stream = new TwitterStream(
                tokens,
                "UofCResearch",
                options);

            Console.WriteLine("stream 1 is starting ...");
            stream.StartPublicStream(
                StreamStopped,
                NewTweet,
                DeletedTweet,
                OtherEvent,
                RawJson);

            Console.WriteLine("stream 1 has started. Press any key to stop.");
            Console.ReadKey();

            Console.WriteLine("Stopping the stream ...");
            stream.EndStream();
        }
示例#12
0
 void StopStream()
 {
     stream.EndStream();
     stream = null;
 }
示例#13
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);

            }
        }
示例#14
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);
 }
示例#15
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);
        }
示例#16
0
 void StartStream()
 {
     if (stream == null) {
         App.ManosTwitter.UserStream((s, callbacks) => {
             stream = s;
             callbacks.StatusCreated += Add;
         });
     }
 }
示例#17
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();
 }
示例#18
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);
        }
示例#19
0
        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);
        }