Quantcast
Channel: Tweetinvi a friendly Twitter C# library
Viewing all articles
Browse latest Browse all 4126

New Post: Can't get more than two multi-threaded filter streams to run

$
0
0
I am building an app that takes saved user OAuth tokens and opens a filtered stream for each one. Eventually it will save the stream somewhere but for now I am just writing it to the console for debugging.

The issue I have is that I am only able to get two streams to return data. Which stream gets to output seems to be random but it is always only two. I am connecting to Twitter using OAuth tokens from different accounts so I shouldn't be getting limited that way if I understand the documentation correctly.

I'm not sure what could be the issue and have been stuck at this problem for some time.

Here is a sample of the code I am running.
public class Program
{
    readonly static string CONSUMER_KEY = "";
    readonly static string CONSUMER_SECRET = "";

    public static void Main(string[] args)
    {
        // Get all Twitter authentications.
        var twitterAuths = new List<TwitterAuth>();
        using (PosterBoardContext context = new PosterBoardContext())
        {
            twitterAuths = context.TwitterAuths.ToList();
        }

        // Start a thread for each Twitter authentication we have.
        Console.WriteLine("Reading Streams for {0} users", twitterAuths.Count);
        foreach (TwitterAuth twitterAuth in twitterAuths)
        {
            Task.Factory.StartNew(() =>
            {
                // Set our user credentials.
                Auth.SetUserCredentials(CONSUMER_KEY, CONSUMER_SECRET, twitterAuth.AccessToken, twitterAuth.AccessTokenSecret);

                // Thread name for debugging and tracking.
                var threadName = "Thread " + twitterAuth.Id;

                // Create the filtered stream.
                var stream = Stream.CreateFilteredStream();

                // Add a track to follow, use something that will get a lot of tweets.
                stream.AddTrack("hello");

                // Write to the console when the stream starts or stops and when we get a matching tweet.
                stream.MatchingTweetReceived += (s, a) => { Console.WriteLine("{0} - {1}", threadName, a.Tweet.Text); };
                stream.StreamStarted += (s, a) => { Console.WriteLine("{0} - Stream Started", threadName); };
                stream.StreamStopped += (s, a) => { Console.WriteLine("{0} - Stream Stopped", threadName); };

                // Start the stream.
                stream.StartStreamMatchingAllConditions();
            });
        }

        Console.ReadKey();
    }
}

Viewing all articles
Browse latest Browse all 4126

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>