Ejemplo n.º 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());
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
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;
 }
        /// <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/1.1/user.json"),
                                                              HTTPVerb.GET, Tokens, userAgent);

#if !SILVERLIGHT
            builder.Proxy = Proxy;
#endif
            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));
        }
        /// <summary>
        ///   Starts the sample stream.
        /// </summary>
        public IAsyncResult StartSampleStream(
            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.1/statuses/sample.json"),
                                                HTTPVerb.POST, userAgent, NetworkCredentials);
            }
            else
            {
                builder = new WebRequestBuilder(new Uri("https://stream.twitter.com/1.1/statuses/sample.json"),
                                                HTTPVerb.POST, Tokens, userAgent);
            }
#if !SILVERLIGHT
            builder.Proxy = Proxy;
#endif
            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));
        }
Ejemplo n.º 6
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);
Ejemplo n.º 7
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));
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
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;
 }
Ejemplo n.º 13
0
            public IAsyncResult StartUserStream(
                FollowingCallback followingCallback = null,
                FollowersCallback followersCallback = null,
                PostsCallback postsCallback         = null,
                MentionsCallback mentionsCallback   = null,
                StreamCallback streamCallback       = null,
                UnifiedCallback unifiedCallback     = null,
                ChannelsCallback channelsCallback   = null,
                ChannelSubscribersCallback channelSubscribersCallback = null,
                ChannelMessagesCallback channelMessagesCallback       = null,
                FilesCallback filesCallback                 = null,
                RawJsonCallback rawJsonCallback             = null,
                StreamStoppedCallback streamStoppedCallback = null)
            {
                if (this.request != null)
                {
                    throw new InvalidOperationException("Stream is already open");
                }

                this.followingCallback          = followingCallback;
                this.followersCallback          = followersCallback;
                this.postsCallback              = postsCallback;
                this.mentionsCallback           = mentionsCallback;
                this.streamCallback             = streamCallback;
                this.unifiedCallback            = unifiedCallback;
                this.channelsCallback           = channelsCallback;
                this.channelSubscribersCallback = channelSubscribersCallback;
                this.channelMessagesCallback    = channelMessagesCallback;
                this.filesCallback              = filesCallback;
                this.rawJsonCallback            = rawJsonCallback;
                this.streamStoppedCallback      = streamStoppedCallback;

                subscribed_endpoints       = new Dictionary <string, StreamingEndpoint>();
                to_be_subscribed_endpoints = new List <StreamingEndpoint>();

                Dictionary <string, string> headers = new Dictionary <string, string>();

                headers.Add("Authorization", "Bearer " + access_token);


                string url = "https://pnut.io/stream/user?ct=AppNet.Net";

                if (streaming_options != null)
                {
                    if (!string.IsNullOrEmpty(streaming_options.query_string()))
                    {
                        url += "&" + streaming_options.query_string();
                    }
                }

                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);

                request.Method            = "GET";
                request.AllowAutoRedirect = true;
                request.Accept            = "*/*";
                request.Timeout           = 10000;
                request.KeepAlive         = true;

                request.UserAgent = "AppNet.Net (http://www.nymphicusapp.com/windows/chapper)";

                foreach (KeyValuePair <string, string> additonalHeader in headers)
                {
                    request.Headers.Add(additonalHeader.Key, additonalHeader.Value);
                }

                try
                {
                    return(request.BeginGetResponse(StreamCallback, request));
                }
                catch (WebException e)
                {
                    Console.WriteLine(e.Message);
                    return(null);
                }
            }
Ejemplo n.º 14
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);

            }
        }
Ejemplo n.º 15
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;
        }