List of usage examples for twitter4j FilterQuery count
int count
To view the source code for twitter4j FilterQuery count.
Click Source Link
From source file:au.net.moon.tStreamingArchiver.Archiver.java
License:Open Source License
/** * Setup log files and then open a Twitter streaming api connection to * collect data.//from ww w . ja v a 2 s .c o m * * @param args * none * @throws TwitterException */ public static void main(String[] args) throws TwitterException { debug = false; if (!debug) { new RedirectSystemLogs("TwitterArchiverLog.%g.log"); } else { System.out.println("TwitterStreamingArchiver: Logging to system log files"); } System.out.println("TwitterStreamingArchiver: Program Starting... (v1.02)"); SearchFilter searchFilter = new SearchFilter(); Archiver archiver = new Archiver(); twitterStream.addListener(archiver); final int historyCount = 0; FilterQuery query = new FilterQuery(); query.follow(searchFilter.followArray()); query.track(searchFilter.trackArray()); query.count(historyCount); twitterStream.filter(query); // TODO: work out how to update the filter when it has changed // searchFilter.update() checks and returns true if searches have // changed. See my notes about how to do it manually. }
From source file:com.esri.geoevent.transport.twitter.TwitterInboundTransport.java
License:Apache License
private void receiveData() { try {// w w w . java 2s. c om applyProperties(); setRunningState(RunningState.STARTED); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true); cb.setOAuthConsumerKey(consumerKey); cb.setOAuthConsumerSecret(consumerSecret); cb.setOAuthAccessToken(accessToken); cb.setOAuthAccessTokenSecret(accessTokenSecret); twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); RawStreamListener rl = new RawStreamListener() { @Override public void onException(Exception ex) { LOGGER.error("INBOUND_TRANSPORT_RAW_STREAM_LISTERNER_EXCEPTION", ex.getMessage()); } @Override public void onMessage(String rawString) { receive(rawString); } }; FilterQuery fq = new FilterQuery(); String keywords[] = tracks; if (follows != null && follows.length > 0) fq.follow(follows); else if (keywords != null && keywords.length > 0) fq.track(keywords); else if (locations != null) fq.locations(locations); else throw new Exception("INBOUND_TRANSPORT_NOFILTER_ERROR"); fq.count(count); LOGGER.info("INBOUND_TRANSPORT_FILTER", filterString); twitterStream.addListener(rl); twitterStream.filter(fq); } catch (Throwable ex) { LOGGER.error("UNEXPECTED_ERROR", ex); setRunningState(RunningState.ERROR); } }
From source file:com.twitstreet.twitter.AdsListenerMgrImpl.java
License:Open Source License
@Override public void start() { TwitterStream twitterStream = new TwitterStreamFactory().getInstance(); Announcer announcer = announcerMgr.randomAnnouncerData(); twitterStream.setOAuthConsumer(announcer.getConsumerKey(), announcer.getConsumerSecret()); twitterStream//w w w . j a v a 2 s. c o m .setOAuthAccessToken(new AccessToken(announcer.getAccessToken(), announcer.getAccessTokenSecret())); twitterStream.addListener(new StatusListener() { @Override public void onException(Exception arg0) { } @Override public void onTrackLimitationNotice(int arg0) { } @Override public void onStatus(Status status) { HashtagEntity[] hashtagEntities = status.getHashtagEntities(); String screenName = status.getUser().getScreenName(); User user = status.getUser(); if (user != null && (System.currentTimeMillis() - lastMessage > TEN_MIN)) { lastMessage = System.currentTimeMillis(); int action = (int) (ACTION_TYPES * Math.random()); switch (action) { case REGULAR_TWEET: LocalizationUtil lutil = LocalizationUtil.getInstance(); int sentenceSize = Integer .parseInt(lutil.get("announcer.sentence.size", LocalizationUtil.DEFAULT_LANGUAGE)); int random = (int) (Math.random() * sentenceSize); String rndMessage = lutil.get("announcer.sentence." + random, LocalizationUtil.DEFAULT_LANGUAGE); announcerMgr.announceFromRandomAnnouncer(rndMessage); break; case RETWEEET: announcerMgr.retweet(status.getId()); break; case FAVOURITE: announcerMgr.favourite(status.getId()); break; default: String message = constructAdsMessage(screenName, hashtagEntities, status.getUser().getLang()); announcerMgr.reply(message, status.getId()); break; } } } @Override public void onScrubGeo(long arg0, long arg1) { } @Override public void onDeletionNotice(StatusDeletionNotice arg0) { } }); FilterQuery filterQuery = new FilterQuery(); filterQuery.count(0); filterQuery.track(FILTER_TERMS); twitterStream.filter(filterQuery); }
From source file:com.twitstreet.twitter.FollowBackMgrImpl.java
License:Open Source License
@Override public void start() { Announcer announcer = announcerMgr.randomAnnouncerData(); twitterProxy = twitterProxyFactory.create(announcer.getAccessToken(), announcer.getAccessTokenSecret()); TwitterStream twitterStream = new TwitterStreamFactory().getInstance(); twitterStream.setOAuthConsumer(announcer.getConsumerKey(), announcer.getConsumerSecret()); twitterStream//from www. j av a2 s.c om .setOAuthAccessToken(new AccessToken(announcer.getAccessToken(), announcer.getAccessTokenSecret())); twitterStream.addListener(new StatusListener() { @Override public void onException(Exception arg0) { } @Override public void onTrackLimitationNotice(int arg0) { } @Override public void onStatus(Status status) { if (System.currentTimeMillis() - lastFollow > FOLLOW_INTERVAL) { twitter4j.User user = status.getUser(); announcerMgr.follow(user.getId()); lastFollow = System.currentTimeMillis(); } // if(System.currentTimeMillis() - lastFollowDiabloBird > FOLLOW_INTERVAL/6){ // twitter4j.User user = status.getUser(); // announcerMgr.followForDiabloBird(user.getId()); // lastFollowDiabloBird = System.currentTimeMillis(); // } } @Override public void onScrubGeo(long arg0, long arg1) { } @Override public void onDeletionNotice(StatusDeletionNotice arg0) { } }); FilterQuery filterQuery = new FilterQuery(); filterQuery.count(0); filterQuery.track(FILTER_TERMS); twitterStream.filter(filterQuery); }
From source file:com.twitstreet.twitter.Welcome2ListenerMgrImpl.java
License:Open Source License
@Override public void start() { Announcer announcer = announcerMgr.randomAnnouncerData(); twitterProxy = twitterProxyFactory.create(announcer.getAccessToken(), announcer.getAccessTokenSecret()); TwitterStream twitterStream = new TwitterStreamFactory().getInstance(); twitterStream.setOAuthConsumer(announcer.getConsumerKey(), announcer.getConsumerSecret()); twitterStream//from www. j a v a2 s . c o m .setOAuthAccessToken(new AccessToken(announcer.getAccessToken(), announcer.getAccessTokenSecret())); twitterStream.addListener(new StatusListener() { @Override public void onException(Exception arg0) { } @Override public void onTrackLimitationNotice(int arg0) { } @Override public void onStatus(Status status) { UserMentionEntity[] userMentionEntities = status.getUserMentionEntities(); for (UserMentionEntity userMentionEntity : userMentionEntities) { idSet.add(userMentionEntity.getId()); if (idSet.size() >= TwitterProxyImpl.IDS_SIZE) { List<User> userList = twitterProxy.getTwUsers(new ArrayList<Long>(idSet)); if (userList != null) { for (User user : userList) { if (user.getFollowersCount() > MIN_FOLLOWER_COUNT_FOR_TREND) { Stock stock = new Stock(user); stockMgr.saveStock(stock); stockMgr.saveTrend(stock.getId()); } } } idSet.clear(); } } } @Override public void onScrubGeo(long arg0, long arg1) { } @Override public void onDeletionNotice(StatusDeletionNotice arg0) { } }); FilterQuery filterQuery = new FilterQuery(); filterQuery.count(0); filterQuery.track(FILTER_TERMS); twitterStream.filter(filterQuery); }
From source file:it.unipr.aotlab.TwitterMiner.twitter.client.TwitterMain.java
License:Open Source License
/** * The args[] are used to filter twitter stream (example: * "#twitter #facebook #social #redis"). If no filter is specified, the * default "#twitter" filter is used/* ww w . ja v a 2 s . c o m*/ * * @param args * @throws FileNotFoundException * @throws TwitterException */ public static void main(String[] args) throws FileNotFoundException { redisDB = new RedisBackend(); listener = new TwitterStreamListener(redisDB); /** Number of old tweets to catch before starting to listen live stream */ int count = 0; TwitterStream twitterStream = new TwitterStreamFactory().getInstance(); twitterStream.addListener(listener); FilterQuery filterQuery = new FilterQuery(); filterQuery.count(count); if (args.length == 0) { args = new String[1]; args[0] = "#twitter"; } filterQuery.track(args); twitterStream.filter(filterQuery); }
From source file:org.wso2.carbon.inbound.custom.poll.TwitterStreamData.java
License:Open Source License
/** * Setting up a connection with Twitter Stream API with the given * credentials/* w w w. j a v a 2s .c o m*/ * * @throws TwitterException */ private void setupConnection() throws TwitterException { if (log.isDebugEnabled()) { log.debug("Starting to setup the connection with the twitter streaming endpoint"); } ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setDebugEnabled(true).setOAuthConsumerKey(consumerKey) .setOAuthConsumerSecret(consumerSecret).setOAuthAccessToken(accessToken) .setOAuthAccessTokenSecret(accessSecret); StatusListener statusStreamsListener; UserStreamListener userStreamListener; SiteStreamsListener siteStreamslistener; TwitterStream twitterStream = new TwitterStreamFactory(configurationBuilder.build()).getInstance(); String twitterOperation = properties.getProperty(TwitterConstant.TWITTER_OPERATION); if (twitterOperation.equals(TwitterConstant.FILTER_STREAM_OPERATION) || twitterOperation.equals(TwitterConstant.FIREHOSE_STREAM_OPERATION) || twitterOperation.equals(TwitterConstant.LINK_STREAM_OPERATION) || twitterOperation.equals(TwitterConstant.SAMPLE_STREAM_OPERATION)) { statusStreamsListener = new StatusListenerImpl(); twitterStream.addListener(statusStreamsListener); } else if (twitterOperation.equals(TwitterConstant.USER_STREAM_OPERATION)) { userStreamListener = new UserStreamListenerImpl(); twitterStream.addListener(userStreamListener); } else if (twitterOperation.equals(TwitterConstant.SITE_STREAM_OPERATION)) { siteStreamslistener = new siteStreamsListenerImpl(); twitterStream.addListener(siteStreamslistener); } else { handleException("The operation :" + twitterOperation + " not found"); } /* Synchronously retrieves public statuses that match one or more filter predicates.*/ if ((properties.getProperty(TwitterConstant.TWITTER_OPERATION)) .equals(TwitterConstant.FILTER_STREAM_OPERATION)) { FilterQuery query = new FilterQuery(); if (languages != null) { query.language(languages); } if (tracks != null) { query.track(tracks); } if (follow != null) { query.follow(follow); } if (filterLevel != null) { query.filterLevel(filterLevel); } query.count(count); twitterStream.filter(query); } /* Returns a small random sample of all public statuses. */ if ((properties.getProperty(TwitterConstant.TWITTER_OPERATION)) .equals(TwitterConstant.SAMPLE_STREAM_OPERATION)) { if (languages != null) { if (languages.length == 1) { twitterStream.sample(languages[1]); } else { handleException("A language can be used for the sample operation"); } } twitterStream.sample(); } /* Asynchronously retrieves all public statuses.*/ if ((properties.getProperty(TwitterConstant.TWITTER_OPERATION)) .equals(TwitterConstant.FIREHOSE_STREAM_OPERATION)) { if (countParam != null) { twitterStream.firehose(count); } } /* User Streams provide a stream of data and events specific to the authenticated user.This provides to access the Streams messages for a single user. */ if ((properties.getProperty(TwitterConstant.TWITTER_OPERATION)) .equals(TwitterConstant.USER_STREAM_OPERATION)) { if (tracks != null) { twitterStream.user(tracks); } twitterStream.user(); } /* * Link Streams provide asynchronously retrieves all statuses containing 'http:' and 'https:'. */ if ((properties.getProperty(TwitterConstant.TWITTER_OPERATION)) .equals(TwitterConstant.LINK_STREAM_OPERATION)) { if (countParam != null) { twitterStream.links(count); } } /* * User Streams provide a stream of data and events specific to the * authenticated user.This provides to access the Streams messages for a * single user. */ if ((properties.getProperty(TwitterConstant.TWITTER_OPERATION)) .equals(TwitterConstant.RETWEET_STREAM_OPERATION)) { twitterStream.retweet(); } /* * Site Streams allows services, such as web sites or mobile push * services, to receive real-time updates for a large number of users. * Events may be streamed for any user who has granted OAuth access to * your application. Desktop applications or applications with few users * should use user streams. */ if ((properties.getProperty(TwitterConstant.TWITTER_OPERATION)) .equals(TwitterConstant.SITE_STREAM_OPERATION)) { twitterStream.site(withFollowings, follow); } }
From source file:org.wso2.carbon.inbound.twitter.poll.TwitterStreamData.java
License:Open Source License
/** * Setting up a connection with Twitter Stream API with the given * credentials// w w w. j a va 2 s. c o m * * @throws TwitterException */ private void setupConnection() throws TwitterException { if (log.isDebugEnabled()) { log.debug("Starting to setup the connection with the twitter streaming endpoint"); } ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setDebugEnabled(true).setJSONStoreEnabled(true).setOAuthConsumerKey(consumerKey) .setOAuthConsumerSecret(consumerSecret).setOAuthAccessToken(accessToken) .setOAuthAccessTokenSecret(accessSecret); StatusListener statusStreamsListener; UserStreamListener userStreamListener; SiteStreamsListener siteStreamslistener; twitterStream = new TwitterStreamFactory(configurationBuilder.build()).getInstance(); String twitterOperation = properties.getProperty(TwitterConstant.TWITTER_OPERATION); if (twitterOperation.equals(TwitterConstant.FILTER_STREAM_OPERATION) || twitterOperation.equals(TwitterConstant.FIREHOSE_STREAM_OPERATION) || twitterOperation.equals(TwitterConstant.LINK_STREAM_OPERATION) || twitterOperation.equals(TwitterConstant.SAMPLE_STREAM_OPERATION) || twitterOperation.equals(TwitterConstant.RETWEET_STREAM_OPERATION)) { statusStreamsListener = new StatusListenerImpl(); twitterStream.addListener(statusStreamsListener); } else if (twitterOperation.equals(TwitterConstant.USER_STREAM_OPERATION)) { userStreamListener = new UserStreamListenerImpl(); twitterStream.addListener(userStreamListener); } else if (twitterOperation.equals(TwitterConstant.SITE_STREAM_OPERATION)) { siteStreamslistener = new siteStreamsListenerImpl(); twitterStream.addListener(siteStreamslistener); } else { handleException("The operation :" + twitterOperation + " not found"); } /* Synchronously retrieves public statuses that match one or more filter predicates.*/ if ((properties.getProperty(TwitterConstant.TWITTER_OPERATION)) .equals(TwitterConstant.FILTER_STREAM_OPERATION)) { FilterQuery query = new FilterQuery(); if (languages != null) { query.language(languages); } if (tracks != null) { query.track(tracks); } if (follow != null) { query.follow(follow); } if (locations != null) { query.locations(locations); } if (filterLevel != null) { query.filterLevel(filterLevel); } if (follow == null & tracks == null & locations == null) { handleException("At least follow, locations, or track must be specified."); } query.count(count); twitterStream.filter(query); } /* Returns a small random sample of all public statuses. */ if ((properties.getProperty(TwitterConstant.TWITTER_OPERATION)) .equals(TwitterConstant.SAMPLE_STREAM_OPERATION)) { if (languages != null) { if (languages.length == 1) { twitterStream.sample(languages[1]); } else { handleException("A language can be used for the sample operation"); } } else { twitterStream.sample(); } } /* Asynchronously retrieves all public statuses.*/ if ((properties.getProperty(TwitterConstant.TWITTER_OPERATION)) .equals(TwitterConstant.FIREHOSE_STREAM_OPERATION)) { if (countParam != null) { twitterStream.firehose(count); } } /* User Streams provide a stream of data and events specific to the authenticated user.This provides to access the Streams messages for a single user. */ if ((properties.getProperty(TwitterConstant.TWITTER_OPERATION)) .equals(TwitterConstant.USER_STREAM_OPERATION)) { if (tracks != null) { twitterStream.user(tracks); } else { twitterStream.user(); } } /* * Link Streams provide asynchronously retrieves all statuses containing 'http:' and 'https:'. */ if ((properties.getProperty(TwitterConstant.TWITTER_OPERATION)) .equals(TwitterConstant.LINK_STREAM_OPERATION)) { if (countParam != null) { twitterStream.links(count); } } /* * User Streams provide a stream of data and events specific to the * authenticated user.This provides to access the Streams messages for a * single user. */ if ((properties.getProperty(TwitterConstant.TWITTER_OPERATION)) .equals(TwitterConstant.RETWEET_STREAM_OPERATION)) { twitterStream.retweet(); } /* * Site Streams allows services, such as web sites or mobile push * services, to receive real-time updates for a large number of users. * Events may be streamed for any user who has granted OAuth access to * your application. Desktop applications or applications with few users * should use user streams. */ if ((properties.getProperty(TwitterConstant.TWITTER_OPERATION)) .equals(TwitterConstant.SITE_STREAM_OPERATION)) { twitterStream.site(withFollowings, follow); } }