/** Call this method to strt reading tweets */ public void readTweets() { /* Create the TweetStream reader thread */ TwitterStream mTwitterStream = new TwitterStreamFactory(this).getInstance("mahateam", "mahateam1"); /* Start reading the Twitter Stream */ mTwitterStream.sample(); }
@Override public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) { statuses = new LinkedBlockingQueue<Status>(1000); this.spoutOutputCollector = collector; ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder .setOAuthConsumerKey(consumerKey) .setOAuthConsumerSecret(consumerSecret) .setOAuthAccessToken(accessToken) .setOAuthAccessTokenSecret(accessTokenSecret); OAuthAuthorization authAuthorization = new OAuthAuthorization(configurationBuilder.build()); twitterStream = new TwitterStreamFactory().getInstance(authAuthorization); twitterStream.addListener( new StatusListener() { @Override public void onStatus(Status status) { statuses.offer(status); } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {} @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) {} @Override public void onScrubGeo(long userId, long upToStatusId) {} @Override public void onStallWarning(StallWarning warning) {} @Override public void onException(Exception ex) {} }); twitter = new TwitterFactory().getInstance(authAuthorization); filterQuery = new FilterQuery(); if (filterQuery == null) { twitterStream.sample(); ; } else { twitterStream.filter(filterQuery.track(filterWords)); twitterStream.filter(filterQuery.language(filterLanguages)); } }