Example #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());
        }
Example #2
0
        /// <summary>
        /// Starts the user stream.
        /// </summary>
        public IAsyncResult StartUserStream(
            InitUserStreamCallback friendsCallback,
            StreamStoppedCallback streamErrorCallback,
            StatusCreatedCallback statusCreatedCallback, 
            StatusDeletedCallback statusDeletedCallback,
            DirectMessageCreatedCallback directMessageCreatedCallback,
            DirectMessageDeletedCallback directMessageDeletedCallback,
            EventCallback eventCallback,
            RawJsonCallback rawJsonCallback = null
            )
        {
            WebRequestBuilder builder = new WebRequestBuilder(new Uri("https://userstream.twitter.com/2/user.json"), HTTPVerb.GET, this.Tokens, true, this.UserAgent);

            PrepareStreamOptions(builder);

            if (this.StreamOptions != null && this.StreamOptions is UserStreamOptions)
            {
                if ((this.StreamOptions as UserStreamOptions).AllReplies)
                    builder.Parameters.Add("replies", "all");
            }

            HttpWebRequest request = builder.PrepareRequest();

            this.friendsCallback = friendsCallback;
            this.streamStoppedCallback = streamErrorCallback;
            this.statusCreatedCallback = statusCreatedCallback;
            this.statusDeletedCallback = statusDeletedCallback;
            this.directMessageCreatedCallback = directMessageCreatedCallback;
            this.directMessageDeletedCallback = directMessageDeletedCallback;
            this.eventCallback = eventCallback;
            this.rawJsonCallback = rawJsonCallback;
            this.stopReceived = false;
            #if SILVERLIGHT
            request.AllowReadStreamBuffering = false;
            #endif
            return request.BeginGetResponse(StreamCallback, request);
        }
Example #3
0
        /// <summary>
        /// Starts the public stream.
        /// </summary>
        public IAsyncResult StartPublicStream(            
            StreamStoppedCallback streamErrorCallback,
            StatusCreatedCallback statusCreatedCallback,
            StatusDeletedCallback statusDeletedCallback,
            EventCallback eventCallback,
            RawJsonCallback rawJsonCallback = null
            )
        {
            WebRequestBuilder builder;
            if (this.Tokens == null)
                builder = new WebRequestBuilder(new Uri("https://stream.twitter.com/1/statuses/filter.json"), HTTPVerb.POST, true, this.UserAgent, this.NetworkCredentials);
            else
                builder = new WebRequestBuilder(new Uri("https://stream.twitter.com/1/statuses/filter.json"), HTTPVerb.POST, this.Tokens, true, this.UserAgent);
            PrepareStreamOptions(builder);

            HttpWebRequest request = builder.PrepareRequest();

            this.streamStoppedCallback = streamErrorCallback;
            this.statusCreatedCallback = statusCreatedCallback;
            this.statusDeletedCallback = statusDeletedCallback;
            this.eventCallback = eventCallback;
            this.rawJsonCallback = rawJsonCallback;
            this.stopReceived = false;
            #if SILVERLIGHT
            request.AllowReadStreamBuffering = false;
            #endif
            return request.BeginGetResponse(StreamCallback, request);
        }
Example #4
0
        /// <summary>
        ///   Starts the public stream.
        /// </summary>
        public IAsyncResult StartPublicStream(
            StreamStoppedCallback streamStoppedCallback,
            StatusCreatedCallback statusCreatedCallback,
            StatusDeletedCallback statusDeletedCallback,
            EventCallback eventCallback,
            RawJsonCallback rawJsonCallback = null
            )
        {
            if (request != null)
            {
                throw new InvalidOperationException("Stream is already open");
            }

            WebRequestBuilder builder;
            if (Tokens == null)
                builder = new WebRequestBuilder(new Uri("https://stream.twitter.com/1/statuses/filter.json"),
                                                HTTPVerb.POST, userAgent, NetworkCredentials);
            else
                builder = new WebRequestBuilder(new Uri("https://stream.twitter.com/1/statuses/filter.json"),
                                                HTTPVerb.POST, Tokens, userAgent);
            PrepareStreamOptions(builder);

            request = builder.PrepareRequest();

            this.streamStoppedCallback = streamStoppedCallback;
            this.statusCreatedCallback = statusCreatedCallback;
            this.statusDeletedCallback = statusDeletedCallback;
            this.eventCallback = eventCallback;
            this.rawJsonCallback = rawJsonCallback;
            stopReceived = false;
#if SILVERLIGHT
            request.AllowReadStreamBuffering = false;
#endif
            return request.BeginGetResponse(StreamCallback, request);
        }
Example #5
0
        /// <summary>
        ///   Starts the user stream.
        /// </summary>
        public IAsyncResult StartUserStream(
            InitUserStreamCallback friendsCallback,
            StreamStoppedCallback streamStoppedCallback,
            StatusCreatedCallback statusCreatedCallback,
            StatusDeletedCallback statusDeletedCallback,
            DirectMessageCreatedCallback directMessageCreatedCallback,
            DirectMessageDeletedCallback directMessageDeletedCallback,
            EventCallback eventCallback,
            RawJsonCallback rawJsonCallback = null
            )
        {
            if (request != null)
            {
                throw new InvalidOperationException("Stream is already open");
            }

            WebRequestBuilder builder = new WebRequestBuilder(new Uri("https://userstream.twitter.com/2/user.json"),
                                                              HTTPVerb.GET, Tokens, userAgent);

            PrepareStreamOptions(builder);

            if (StreamOptions != null && StreamOptions is UserStreamOptions)
            {
                if ((StreamOptions as UserStreamOptions).AllReplies)
                    builder.Parameters.Add("replies", "all");
            }

            request = builder.PrepareRequest();
            this.friendsCallback = friendsCallback;
            this.streamStoppedCallback = streamStoppedCallback;
            this.statusCreatedCallback = statusCreatedCallback;
            this.statusDeletedCallback = statusDeletedCallback;
            this.directMessageCreatedCallback = directMessageCreatedCallback;
            this.directMessageDeletedCallback = directMessageDeletedCallback;
            this.eventCallback = eventCallback;
            this.rawJsonCallback = rawJsonCallback;
            stopReceived = false;
#if SILVERLIGHT
            request.AllowReadStreamBuffering = false;
#else
            request.Timeout = 10000;
#endif
            return request.BeginGetResponse(StreamCallback, request);
        }
Example #6
0
 /// <summary>
 ///   Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     EndStream();
     friendsCallback = null;
     streamStoppedCallback = null;
     statusCreatedCallback = null;
     statusDeletedCallback = null;
     directMessageCreatedCallback = null;
     directMessageDeletedCallback = null;
     eventCallback = null;
     rawJsonCallback = null;
 }
Example #7
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);

            }
        }
Example #8
0
        /// <summary>
        ///   Starts the user stream.
        /// </summary>
        public async void StartUserStream(
            InitUserStreamCallback friendsCallback,
            StreamStoppedCallback streamStoppedCallback,
            StatusCreatedCallback statusCreatedCallback,
            StatusDeletedCallback statusDeletedCallback,
            DirectMessageCreatedCallback directMessageCreatedCallback,
            DirectMessageDeletedCallback directMessageDeletedCallback,
            EventCallback eventCallback,
            RawJsonCallback rawJsonCallback = null
            )
        {
            if (request != null)
            {
                throw new InvalidOperationException("Stream is already open");
            }

            WebRequestBuilder builder = new WebRequestBuilder(new Uri("https://userstream.twitter.com/2/user.json"),
                                                              HttpMethod.Get, Tokens, userAgent);

            PrepareStreamOptions(builder);

            if (StreamOptions != null && StreamOptions is UserStreamOptions)
            {
                if ((StreamOptions as UserStreamOptions).AllReplies)
                    builder.Parameters.Add("replies", "all");
            }

            request = await builder.PrepareRequestAsync();
            this.friendsCallback = friendsCallback;
            this.streamStoppedCallback = streamStoppedCallback;
            this.statusCreatedCallback = statusCreatedCallback;
            this.statusDeletedCallback = statusDeletedCallback;
            this.directMessageCreatedCallback = directMessageCreatedCallback;
            this.directMessageDeletedCallback = directMessageDeletedCallback;
            this.eventCallback = eventCallback;
            this.rawJsonCallback = rawJsonCallback;
            stopReceived = false;
            //request.DefaultRequestHeaders.Timeout = 10000;
            return client.GetAsync(request);..BeginGetResponse(StreamCallback, request);
            return null;
        }
Example #9
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);
 }