Running multiple rules listeners in Twitter4j

twitter4j
java

#1

I am trying to use the Twitter4j API to track twitts according to some rule criteria. The API works fine when there is one rule, but when I am adding two or three rules I am getting this error:

420:Returned by the Search and Trends API when you are being rate limited     (https://dev.twitter.com/docs/rate-limiting).
Returned by the Streaming API:
Too many login attempts in a short period of time.
Running too many copies of the same application authenticating with the same account name.
Exceeded connection limit for user

The code I’m using is:

// create the TwitterStream object

ConfigurationBuilder cb = new ConfigurationBuilder();

cb.setDebugEnabled(false).setOAuthConsumerKey(accountdetails.ConsumerKey)
                .setOAuthConsumerSecret(accountdetails.ConsumerSecret)
                .setOAuthAccessToken(accountdetails.AccessToken)
                .setOAuthAccessTokenSecret(accountdetails.AccessTokenSecret)

Configuration config = cb.build();

TwitterStream twitterStream = new 
TwitterStreamFactory(config).getInstance();

// create the filter

FilterQuery filter = new FilterQuery();
filter.track(trackList);

// create the Listener object

// Twitter4jListener is a class that implements the StatusListener interface
Twitter4jListener listener = new Twitter4jListener(rule);
twitterStream.addListener(listener);
twitterStream.filter(filter);

Do I use the API incorrectly? or the API generally have a limit on a number of Listeners that can work in parallel?


#2

The public Filter stream is only available for a single rule filter. You could try combining your two or three rules using a comma to represent an OR-like operator: https://dev.twitter.com/streaming/overview/request-parameters#track

Rules on the public filter stream can be up to 500 characters. If you need multiple rules on a stream or longer and more complex rules, please contact Gnip: https://gnip.com/