Shravan Ashok
Shravan Ashok

Reputation: 1

How to listen to thousands of twitter accounts simultaneously?

I am in the process of building an app that will monitor multiple Twitter accounts(~10K) for their most recent activities and perform some analysis based on that. I am able to create a listener for one such twitter account and do the processing through the streaming API provided by Twitter4j. However, I am not able to figure out how to replicate this model for thousands of accounts in parallel. Tried looking for it over the web but could not find any satisfactory answer. Is it actually achievable? Or do I need to think of some other approach? Any help would be highly appreciated.

Thank you!

Upvotes: 0

Views: 187

Answers (1)

FeanDoe
FeanDoe

Reputation: 1668

If you want to follow some users you should use a filter. The Twitter Api let you follow up to 5000 users by their id with one credential, like this:

StatusListener statusListener = new StatusListener() {
    @Override
    public void onStatus(Status status) {
        //your code to manage the statuses
    }
    //other requiredly-overriden methods
}
ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
configurationBuilder.setOAuthConsumerKey("XXXXX");
configurationBuilder.setOAuthConsumerSecret("XXXXXXX");
TwitterStream twitterStream = new TwitterStreamFactory(configurationBuilder.build()).getInstance(new AccessToken("XXXXX", "XXXXXXX"));
twitterStream.addListener(statusListener);

//from here is different at your code

//you need to set up your user list, with their users id's!
long[] userslist = YOUR USER LIST;
//then you create a filter
FilterQuery filtre = new FilterQuery();
//and use that filter to follow the users that you want and to start the stream
filtre.follow(userslist);
twitterStream.filter(filtre);

With the filter you could follow up to 5000 different users and you will get what they tweet, when they are being retweeted and when they are being mentioned.

Upvotes: 0

Related Questions