/// <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)); }
/// <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 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 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)); }
/// <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);
/// <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)); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
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); } }
/// <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; }