List of usage examples for twitter4j TwitterStreamFactory TwitterStreamFactory
public TwitterStreamFactory()
From source file:stream.PrintSampleStream.java
License:Apache License
/** * Main entry of this application./*from w ww . j a v a 2s . c om*/ * * @param args */ public static void main(String[] args) throws TwitterException { TwitterStream twitterStream = new TwitterStreamFactory().getInstance(); StatusListener listener = new StatusListener() { public void onStatus(Status status) { System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText()); } public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId()); } public void onTrackLimitationNotice(int numberOfLimitedStatuses) { System.out.println("Got track limitation notice:" + numberOfLimitedStatuses); } public void onScrubGeo(long userId, long upToStatusId) { System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId); } public void onException(Exception ex) { ex.printStackTrace(); } }; twitterStream.addListener(listener); twitterStream.sample(); }
From source file:stream.PrintSiteStreams.java
License:Apache License
/** * Main entry of this application./*from w ww. j a v a 2s . co m*/ * * @param args follow(comma separated user ids) track(comma separated filter terms) * @throws twitter4j.TwitterException */ public static void main(String[] args) throws TwitterException { if (args.length < 1) { System.out.println( "Usage: java twitter4j.examples.PrintSiteStreams [follow(comma separated numerical user ids)]"); System.exit(-1); } TwitterStream twitterStream = new TwitterStreamFactory().getInstance(); twitterStream.addListener(listener); String[] split = args[0].split(","); long[] followArray = new long[split.length]; for (int i = 0; i < followArray.length; i++) { followArray[i] = Long.parseLong(split[i]); } // site() method internally creates a thread which manipulates TwitterStream and calls these adequate listener methods continuously. twitterStream.site(true, followArray); }
From source file:sumblr.TwitterStreamData.java
public TwitterStreamData() { this.oathAccessToken = new AccessToken(ACCESS_TOKEN, ACCESS_TOKEN_SECRET); this.twitterStream = new TwitterStreamFactory().getInstance(); this.twitterStream.setOAuthConsumer(CONSUMER_KEY, CONSUMER_KEY_SECRET); this.twitterStream.setOAuthAccessToken(oathAccessToken); this.fq = new FilterQuery(); preprocessor = new Preprocessor(); }
From source file:trendulo.ingest.twitter.TwitterStreamingStringSequenceSource.java
License:Apache License
public TwitterStreamingStringSequenceSource(String username, String password, String archiveTwitterFilePath, StatusFilter statusFilter) {//from w w w .j a v a2s . c o m this.statusFilter = statusFilter; statusQueue = new ArrayBlockingQueue<Status>(DEFAULT_BUFFER_SIZE); // If the user wants status messages archived, create an OutputStream if (archiveTwitterFilePath != null) { try { // Verify that the file doesn't already exist so we don't clobber the archive if (new File(archiveTwitterFilePath).exists()) { throw new RuntimeException( "Archive File Already Exists. Please move/rename before starting Ingest: " + archiveTwitterFilePath); } FileOutputStream fos = new FileOutputStream(archiveTwitterFilePath); if (archiveTwitterFilePath.endsWith("gz")) { archiveOutputStream = new GZIPOutputStream(new BufferedOutputStream(fos)); } else { archiveOutputStream = fos; } } catch (IOException e) { log.error("Error creating archive file", e); } } // Configure the Twitter Streaming API client // this system property is required to access raw json System.setProperty("twitter4j.jsonStoreEnabled", "true"); auth = new BasicAuthorization(username, password); twitterStream = new TwitterStreamFactory().getInstance(auth); twitterStream.addListener(this); // We only want status messages with a geo. This needs to be pulled // out so it is configurable // Right now just the lower 48 of the US FilterQuery filterQuery = new FilterQuery(); double[][] locations = { { -126.0, 24.0 }, { -67.0, 49.0 } }; filterQuery.locations(locations); twitterStream.filter(filterQuery); }
From source file:tweet.streams.TwitterCrawler.java
License:Apache License
public static void main(String[] args) { initFile();/*from ww w.ja va2 s . c o m*/ TwitterStream twitterStream = new TwitterStreamFactory().getInstance(); twitterStream.addListener(listener); // FilterQuery query = new FilterQuery().language("EN").track(seeds); // twitterStream.filter(query); twitterStream.sample(); }
From source file:twitter.stream.PrintFilterStream.java
License:Apache License
public static void main(String[] args) throws TwitterException, IOException { if (args.length < 1) { System.out.println(/* w w w. ja v a2s .c om*/ "Usage: java twitter4j.examples.PrintFilterStream [follow(comma separated numerical user ids)] [track(comma separated filter terms)]"); System.exit(-1); } final ConnectionManager c = new ConnectionManager(); try { c.createConnection(); c.createDB(); c.closeConnection(); } catch (SQLException e) { // TODO Auto-generated catch block System.out.println(e); } System.out.println("conexion creada"); StatusListener listener = new StatusListener() { @Override public void onStatus(Status status) { // pw.println("@" + status.getUser().getScreenName() + " - " + status.getText()); // if (status.getGeoLocation() != null) // pw.println("Lat:" + status.getGeoLocation().getLatitude() + "Long" // + status.getGeoLocation().getLongitude()); // User u = status.getUser(); // try { // System.out.println("User: id: " + u.getId() + " name: " + u.getName()); // c.insertTwitterUser(u); // } catch (SQLException e1) { // // TODO Auto-generated catch block // System.out.println(e1); // } // // if (status.isRetweet()) { // // System.out.println("RT Found!, getting the original tweet"); // Status retweetedStat = status.getRetweetedStatus(); // u = retweetedStat.getUser(); // System.out.println("RT User: id: " + u.getId() + " name: " + u.getName()); // // try { // // c.insertTwitterUser(u); // // c.insertTweet(retweetedStat); // // // // // } catch (SQLException e) { // // TODO Auto-generated catch block // System.out.println(e); // } // // } // if(status.getQuotedStatus() != null){ // // System.out.println("Quoted Found!, getting the original tweet"); // Status quotedStatus = status.getQuotedStatus(); // u = quotedStatus.getUser(); // System.out.println("Quoted User: id: " + u.getId() + " name: " + u.getName()); // // try { // c.insertTwitterUser(u); // c.insertTweet(quotedStatus); // } catch (SQLException e) { // // TODO Auto-generated catch block // System.out.println(e); // } // } // // // // try { // c.insertTweet(status); // } catch (SQLException e) { // // TODO Auto-generated catch block // System.out.println(e); // } try { c.recursiveInsert(status, 0); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId()); } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { System.out.println("Got track limitation notice:" + numberOfLimitedStatuses); } @Override public void onScrubGeo(long userId, long upToStatusId) { System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId); } @Override public void onStallWarning(StallWarning warning) { System.out.println("Got stall warning:" + warning); } @Override public void onException(Exception ex) { ex.printStackTrace(); } }; TwitterStream twitterStream = new TwitterStreamFactory().getInstance(); FilterQuery fq = new FilterQuery(); String keywords[] = { "election2016", "NeverTrump", "Hillary2016", "Trump", "HillarysEmail", "2016election" }; fq.track(keywords); twitterStream.addListener(listener); twitterStream.filter(fq); }
From source file:twitter.stream.PrintSampleStream.java
License:Apache License
/** * Main entry of this application.//from www . j a v a 2 s . c om * * @param args * arguments doesn't take effect with this example * @throws TwitterException * when Twitter service or network is unavailable */ public static void main(String[] args) throws TwitterException { TwitterStream twitterStream = new TwitterStreamFactory().getInstance(); StatusListener listener = new StatusListener() { @Override public void onStatus(Status status) { if (status.getGeoLocation() != null) System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText() + "Lat:" + status.getGeoLocation().getLatitude() + "Long" + status.getGeoLocation().getLongitude()); } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { // System.out.println("Got a status deletion notice id:" + // statusDeletionNotice.getStatusId()); } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { // System.out.println("Got track limitation notice:" + // numberOfLimitedStatuses); } @Override public void onScrubGeo(long userId, long upToStatusId) { // System.out.println("Got scrub_geo event userId:" + userId + " // upToStatusId:" + upToStatusId); } @Override public void onStallWarning(StallWarning warning) { System.out.println("Got stall warning:" + warning); } @Override public void onException(Exception ex) { ex.printStackTrace(); } }; twitterStream.addListener(listener); twitterStream.sample(); }
From source file:twitter4j.examples.stream.PrintFilterStream.java
License:Apache License
/** * Main entry of this application./*from w w w.ja va 2 s.com*/ * * @param args follow(comma separated user ids) track(comma separated filter terms) * @throws TwitterException when Twitter service or network is unavailable */ public static void main(String[] args) throws TwitterException { if (args.length < 1) { System.out.println( "Usage: java twitter4j.examples.PrintFilterStream [follow(comma separated numerical user ids)] [track(comma separated filter terms)]"); System.exit(-1); } TwitterStream twitterStream = new TwitterStreamFactory().getInstance().addListener(new StatusListener() { @Override public void onStatus(Status status) { System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText()); } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId()); } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { System.out.println("Got track limitation notice:" + numberOfLimitedStatuses); } @Override public void onScrubGeo(long userId, long upToStatusId) { System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId); } @Override public void onStallWarning(StallWarning warning) { System.out.println("Got stall warning:" + warning); } @Override public void onException(Exception ex) { ex.printStackTrace(); } }); ArrayList<Long> follow = new ArrayList<Long>(); ArrayList<String> track = new ArrayList<String>(); for (String arg : args) { if (isNumericalArgument(arg)) { for (String id : arg.split(",")) { follow.add(Long.parseLong(id)); } } else { track.addAll(Arrays.asList(arg.split(","))); } } long[] followArray = new long[follow.size()]; for (int i = 0; i < follow.size(); i++) { followArray[i] = follow.get(i); } String[] trackArray = track.toArray(new String[track.size()]); // filter() method internally creates a thread which manipulates TwitterStream and calls these adequate listener methods continuously. twitterStream.filter(new FilterQuery(0, followArray, trackArray)); }
From source file:twitter4j.examples.stream.PrintFirehoseStream.java
License:Apache License
/** * Main entry of this application.//from w w w .j av a 2 s .c om * * @param args arguments doesn't take effect with this example * @throws TwitterException when Twitter service or network is unavailable */ public static void main(String[] args) throws TwitterException { TwitterStream twitterStream = new TwitterStreamFactory().getInstance().addListener(new StatusListener() { @Override public void onStatus(Status status) { System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText()); } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId()); } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { System.out.println("Got track limitation notice:" + numberOfLimitedStatuses); } @Override public void onScrubGeo(long userId, long upToStatusId) { System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId); } @Override public void onStallWarning(StallWarning warning) { System.out.println("Got stall warning:" + warning); } @Override public void onException(Exception ex) { ex.printStackTrace(); } }).firehose(0); }
From source file:twitter4j.examples.stream.PrintLinksStream.java
License:Apache License
/** * Main entry of this application./*w w w .j a v a 2 s. c o m*/ * * @param args arguments doesn't take effect with this example * @throws TwitterException when Twitter service or network is unavailable */ public static void main(String[] args) throws TwitterException { TwitterStream twitterStream = new TwitterStreamFactory().getInstance().addListener(new StatusListener() { @Override public void onStatus(Status status) { System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText()); } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId()); } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { System.out.println("Got track limitation notice:" + numberOfLimitedStatuses); } @Override public void onScrubGeo(long userId, long upToStatusId) { System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId); } @Override public void onStallWarning(StallWarning warning) { System.out.println("Got stall warning:" + warning); } @Override public void onException(Exception ex) { ex.printStackTrace(); } }).links(0); }