List of usage examples for twitter4j FilterQuery follow
null follow
To view the source code for twitter4j FilterQuery follow.
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./* w w w . java 2 s .c om*/ * * @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:be.ugent.tiwi.sleroux.newsrec.newsreclib.newsFetch.storm.spouts.TweetsSpout.java
License:Apache License
private FilterQuery getFilterQuery() throws DaoException { FilterQuery f = new FilterQuery(); List<Long> users = followersDao.getUsersToFollow(); long[] usersArray = new long[users.size()]; int i = 0;/*from w ww . jav a 2s .c o m*/ for (Long l : users) { usersArray[i] = l; i++; } f.follow(usersArray); return f; }
From source file:be.ugent.tiwi.sleroux.newsrec.twittertest.StreamReaderService.java
public void readTwitterFeed() { TwitterStream stream = TwitterStreamBuilderUtil.getStream(); StatusListener listener = new StatusListener() { @Override/* ww w . java 2 s . co m*/ public void onException(Exception e) { } @Override public void onTrackLimitationNotice(int n) { } @Override public void onStatus(Status status) { if (status.getLang().equals("en")) { System.out.println(status.getText()); } } @Override public void onStallWarning(StallWarning arg0) { } @Override public void onScrubGeo(long arg0, long arg1) { } @Override public void onDeletionNotice(StatusDeletionNotice arg0) { } }; stream.addListener(listener); FilterQuery f = new FilterQuery(); f.language(new String[] { "en" }); f.follow(new long[] { 816653 }); stream.filter(f); try { Thread.sleep(60000); } catch (InterruptedException ex) { Logger.getLogger(StreamReaderService.class.getName()).log(Level.SEVERE, null, ex); } stream.shutdown(); }
From source file:br.com.porcelli.hornetq.integration.twitter.stream.impl.StatusStreamHandler.java
License:Apache License
@Override public void startStream() throws TwitterException { if (data.getMentionedUsers() != null || data.getHashTags() != null) { final FilterQuery fq = new FilterQuery(); if (data.getUserIds() != null) { fq.follow(data.getUserIds()); }//from w w w.ja v a 2 s .c o m if (data.getHashTags() != null) { fq.track(data.getHashTags()); } twitterStream.filter(fq); } else { twitterStream.firehose(1000); } }
From source file:cc.twittertools.stream.GatherStatusStream.java
License:Apache License
public static void main(String[] args) throws TwitterException { PatternLayout layoutStandard = new PatternLayout(); layoutStandard.setConversionPattern("[%p] %d %c %M - %m%n"); PatternLayout layoutSimple = new PatternLayout(); layoutSimple.setConversionPattern("%m%n"); // Filter for the statuses: we only want INFO messages LevelRangeFilter filter = new LevelRangeFilter(); filter.setLevelMax(Level.INFO); filter.setLevelMin(Level.INFO); filter.setAcceptOnMatch(true);//from ww w . j av a 2s . c o m filter.activateOptions(); TimeBasedRollingPolicy statusesRollingPolicy = new TimeBasedRollingPolicy(); statusesRollingPolicy.setFileNamePattern("statuses.log" + HOUR_ROLL); statusesRollingPolicy.activateOptions(); RollingFileAppender statusesAppender = new RollingFileAppender(); statusesAppender.setRollingPolicy(statusesRollingPolicy); statusesAppender.addFilter(filter); statusesAppender.setLayout(layoutSimple); statusesAppender.activateOptions(); TimeBasedRollingPolicy warningsRollingPolicy = new TimeBasedRollingPolicy(); warningsRollingPolicy.setFileNamePattern("warnings.log" + HOUR_ROLL); warningsRollingPolicy.activateOptions(); RollingFileAppender warningsAppender = new RollingFileAppender(); warningsAppender.setRollingPolicy(statusesRollingPolicy); warningsAppender.setThreshold(Level.WARN); warningsAppender.setLayout(layoutStandard); warningsAppender.activateOptions(); ConsoleAppender consoleAppender = new ConsoleAppender(); consoleAppender.setThreshold(Level.WARN); consoleAppender.setLayout(layoutStandard); consoleAppender.activateOptions(); // configures the root logger Logger rootLogger = Logger.getRootLogger(); rootLogger.setLevel(Level.INFO); rootLogger.removeAllAppenders(); rootLogger.addAppender(consoleAppender); rootLogger.addAppender(statusesAppender); rootLogger.addAppender(warningsAppender); // creates a custom logger and log messages final Logger logger = Logger.getLogger(GatherStatusStream.class); TwitterStream twitterStream = new TwitterStreamFactory().getInstance(); RawStreamListener rawListener = new RawStreamListener() { @Override public void onMessage(String rawString) { cnt++; logger.info(rawString); if (cnt % 100 == 0) { System.out.println(cnt + " messages received."); } } @Override public void onException(Exception ex) { logger.warn(ex); } }; twitterStream.addListener(rawListener); FilterQuery fq = new FilterQuery(); /* double locations[][]={{112.0,-44.0},{155.0,-10.5}}; fq.locations(locations);*/ long ids[] = { 87818409, 16675569 }; fq.follow(ids); twitterStream.filter(fq); //twitterStream.sample(); }
From source file:cloudcomputebot.CloudComputeBot.java
License:Open Source License
public static void main(String[] args) { TwitterLib.init();/*from w w w.j a v a 2s . c o m*/ t = TwitterLib.t; TwitterStreamFactory twitterStreamFactory = new TwitterStreamFactory(t.getConfiguration()); TwitterStream twitterStream = twitterStreamFactory.getInstance(); FilterQuery filterQuery = new FilterQuery(); filterQuery.follow(new long[] { 4741197613L }); twitterStream.addListener(new MentionListener()); twitterStream.filter(filterQuery); }
From source file:com.aremaitch.codestock2010.library.TwitterLib.java
License:Apache License
public void startMonitoringStream(String[] hashTags, long[] userIds, StatusListener statusListener, ConnectionLifeCycleListener connectionLifeCycleListener) throws TwitterException { if (statusListener != null) tStream.addListener(statusListener); if (connectionLifeCycleListener != null) tStream.addConnectionLifeCycleListener(connectionLifeCycleListener); FilterQuery fq = new FilterQuery(); fq.track(hashTags);/*from w ww. j ava 2s . c o m*/ if (userIds != null) fq.follow(userIds); tStream.filter(fq); }
From source file:com.esri.geoevent.transport.twitter.TwitterInboundTransport.java
License:Apache License
private void receiveData() { try {//from w ww .ja va 2 s .c o m 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.isdp.twitterposter.TwitterManager.java
License:Open Source License
public void startTwitterStream() { TwitterStream twitterStream = new TwitterStreamFactory(configuration).getInstance(); StatusListener listener = new StatusListener() { @Override/*from w w w . j a v a 2 s . c o m*/ public void onStatus(Status status) { try { System.out.println("Text recieved: @" + status.getUser().getScreenName() + " - " + status.getText() + "\n"); StringTokenizer st = new StringTokenizer(status.getText(), " "); //first token indicates search engine String searchEngine = st.nextToken(); //burn the next random token String randToken = st.nextToken(); //next token indicates max number of results to return int maxResults = Integer.parseInt(st.nextToken()); String searchString = ""; while (st.hasMoreTokens()) { searchString += st.nextToken() + " "; } if (searchEngine.equals(GoogleManager.TAG_YELP)) { String[] results = GoogleManager.getInstance().trySearch(searchString, GoogleManager.SEARCH_YELP); if (results != null) { for (int i = 0; i < results.length && i < maxResults; ++i) { String tweetMsg = Util.truncateString(results[i], TWITTER_CHARACTER_LIMIT); System.out.println("Tweeting" + tweetMsg); tweet(tweetMsg); } } else if (results == null || results.length == 0) { tweet(Util.generateRandomString(7) + "\n" + "No results found!"); } } else if (searchEngine.equals(GoogleManager.TAG_WIKI)) { String[] results = GoogleManager.getInstance().trySearch(searchString, GoogleManager.SEARCH_WIKI); if (results != null) { for (int i = 0; i < results.length && i < maxResults; ++i) { String tweetMsg = Util.generateRandomString(3) + "\n" + Util.shortenText(results[i]); tweetMsg = Util.truncateString(tweetMsg, TWITTER_CHARACTER_LIMIT); System.out.println("Tweeting " + tweetMsg); tweet(tweetMsg); } } else if (results == null || results.length == 0) { tweet(Util.generateRandomString(7) + "\n" + "No results found!"); } } } catch (Exception e) { } } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { System.out.println( "onDeletionNotice: Got a status deletion notice id:" + statusDeletionNotice.getStatusId()); } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { System.out .println("onTrackLimitationNotice: Got track limitation notice:" + numberOfLimitedStatuses); } @Override public void onScrubGeo(long userId, long upToStatusId) { System.out.println( "onScrubGeo: Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId); } @Override public void onStallWarning(StallWarning warning) { System.out.println("onStallWarning: Got stall warning:" + warning); } @Override public void onException(Exception ex) { System.out.println("onException" + ex.toString()); } }; twitterStream.addListener(listener); FilterQuery tweetFilterQuery = new FilterQuery(); tweetFilterQuery.follow(new long[] { FOLLOW_ID }); twitterStream.filter(tweetFilterQuery); }
From source file:com.isdp.twitterposterandroid.TwitterManager.java
License:Open Source License
public void startTwitterStream() { TwitterStream twitterStream = new TwitterStreamFactory(configuration).getInstance(); StatusListener listener = new StatusListener() { @Override/*from w ww . j a v a 2 s .co m*/ public void onStatus(Status status) { try { Log.d("Text recieved", "@" + status.getUser().getScreenName() + " - " + status.getText() + "\n"); StringTokenizer st = new StringTokenizer(status.getText(), " "); //first token indicates search engine String searchEngine = st.nextToken(); //burn the next random token String randToken = st.nextToken(); //next token indicates max number of results to return int maxResults = Integer.parseInt(st.nextToken()); String searchString = ""; while (st.hasMoreTokens()) { searchString += st.nextToken() + " "; } if (searchEngine.equals(GoogleManager.TAG_YELP)) { String[] results = GoogleManager.getInstance().trySearch(searchString, GoogleManager.SEARCH_YELP); if (results != null) { for (int i = 0; i < results.length && i < maxResults; ++i) { String tweetMsg = Util.truncateString(results[i], TWITTER_CHARACTER_LIMIT); Log.d("Tweeting", tweetMsg); tweet(tweetMsg); } } else if (results == null || results.length == 0) { tweet(Util.generateRandomString(7) + "\n" + "No results found!"); } } else if (searchEngine.equals(GoogleManager.TAG_WIKI)) { String[] results = GoogleManager.getInstance().trySearch(searchString, GoogleManager.SEARCH_WIKI); if (results != null) { for (int i = 0; i < results.length && i < maxResults; ++i) { String tweetMsg = Util.generateRandomString(3) + "\n" + Util.shortenText(results[i]); tweetMsg = Util.truncateString(tweetMsg, TWITTER_CHARACTER_LIMIT); Log.d("Tweeting", tweetMsg); tweet(tweetMsg); } } else if (results == null || results.length == 0) { tweet(Util.generateRandomString(7) + "\n" + "No results found!"); } } } catch (Exception e) { } } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { Log.d("onDeletionNotice", "Got a status deletion notice id:" + statusDeletionNotice.getStatusId()); } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { Log.d("onTrackLimitationNotice", "Got track limitation notice:" + numberOfLimitedStatuses); } @Override public void onScrubGeo(long userId, long upToStatusId) { Log.d("onScrubGeo", "Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId); } @Override public void onStallWarning(StallWarning warning) { Log.d("onStallWarning", "Got stall warning:" + warning); } @Override public void onException(Exception ex) { Log.d("onException", ex.toString()); } }; twitterStream.addListener(listener); FilterQuery tweetFilterQuery = new FilterQuery(); tweetFilterQuery.follow(new long[] { FOLLOW_ID }); twitterStream.filter(tweetFilterQuery); }