private void OnUserAddedToDataStore(object sender, UserChangedEventArgs args) { _stream.PauseStream(); if (args.NewUser != null) { _stream.AddFollow(args.NewUser.Id); } if (args.OldUser != null) { _stream.RemoveFollow(args.OldUser.Id); } _stream.ResumeStream(); }
/// <summary> /// Starts a Twitter Stream based on the specified geographic coordinates and the now playing hash tag /// </summary> /// <param name="latitude1">Latitude of user location (bottom_left)</param> /// <param name="longitude1">Longitude of user location (bottom_left)</param> /// <param name="latitude2">Latitude of user location (top_right)</param> /// <param name="longitude2">Longitude of user location (top_right)</param> public static async Task StartStream(double latitude1, double longitude1, double latitude2, double longitude2) { // Setup Twitter credentials TweetinviUtilities.SetTwitterCredentials(); // If the stream does not exists... if (_stream == null) { //...then it is started // Create a filtered stream _stream = Stream.CreateFilteredStream(); _stream.AddTrack(Constants.NOWPLAYING_HASHTAG); // Lookup for nowplaying hashtag // OPTIONAL: if you want to see how the feed is updated really quick, just comment the following line of code. // You will see the effect of "infinite scroll" in the client _stream.AddLocation( new Coordinates(latitude1, longitude1), new Coordinates(latitude2, longitude2)); // Lookup in the specific geographic coordinates // OPTIONAL: if you want to filter the stream just for a specific user, uncomment the following line of code //_stream.AddFollow(2834545563); // Event that handles a matching tweet _stream.MatchingTweetReceived += async(sender, args) => { // A OEmbed tweet is sent to the client IOEmbedTweet embedTweet = Tweet.GetOEmbedTweet(args.Tweet); await _context.Clients.All.updateFeed(embedTweet); }; // Start the stream matching all conditions await _stream.StartStreamMatchingAllConditionsAsync(); } else { //... otherwise resume it _stream.ResumeStream(); } }
private async void MinuteTimerEventHandler(object sender, System.Timers.ElapsedEventArgs e) { CheckTwitterFollows(); if (_twitterStream == null) { return; } switch (_twitterStream.StreamState) { case StreamState.Running: break; case StreamState.Pause: _twitterStream.ResumeStream(); break; case StreamState.Stop: await _twitterStream.StartStreamMatchingAllConditionsAsync(); break; } }
public static async Task StartStream() { var consumerKey = Environment.GetEnvironmentVariable("TWITTER_CONSUMER_KEY", EnvironmentVariableTarget.User); var consumerSecret = Environment.GetEnvironmentVariable("TWITTER_CONSUMER_SECRET", EnvironmentVariableTarget.User); var accessToken = Environment.GetEnvironmentVariable("TWITTER_ACCESS_TOKEN", EnvironmentVariableTarget.User); var accessTokenSecret = Environment.GetEnvironmentVariable("TWITTER_ACCESS_TOKEN_SECRET", EnvironmentVariableTarget.User); var credentials = Auth.SetUserCredentials(consumerKey, consumerSecret, accessToken, accessTokenSecret); if (_stream == null) { _stream = Stream.CreateFilteredStream(credentials); _stream.AddTrack("#WorldCup"); _stream.MatchingTweetReceived += async(sender, args) => { await HubContext.Clients.All.SendTweet(args.Tweet.FullText); }; await _stream.StartStreamMatchingAllConditionsAsync(); } else { _stream.ResumeStream(); } }