List of usage examples for twitter4j FilterQuery FilterQuery
public FilterQuery(String... track)
From source file:public_streaming.UserIDStream.java
License:Apache License
public static void main(String[] args) throws Exception { Configuration configuration = new ConfigurationBuilder().setOAuthConsumerKey(CONSUMER_KEY) .setOAuthConsumerSecret(CONSUMER_SECRET).setOAuthAccessToken(ACCESS_TOKEN) .setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET).build(); TwitterStream twStream = new TwitterStreamFactory(configuration).getInstance(); twStream.addListener(new MyStatusListener()); ///*from w w w . j av a 2 s .com*/ long[] follow = { 1598997848 };//anondroid3?id:1598997848 FilterQuery filter = new FilterQuery(follow);//?userID????? twStream.filter(filter); }
From source file:site_streaming.SiteStream.java
License:Apache License
public static void main(String[] args) throws Exception { Configuration configuration = new ConfigurationBuilder().setOAuthConsumerKey(CONSUMER_KEY) .setOAuthConsumerSecret(CONSUMER_SECRET).setOAuthAccessToken(ACCESS_TOKEN) .setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET) .setSiteStreamBaseURL("https://sitestream.twitter.com/1.1/site.json").build(); TwitterStream SiteStream = new TwitterStreamFactory(configuration).getInstance(); SiteStream.addListener(new MyStatusListener()); long[] follow = { 1598997848 };//anondroid3?id:1598997848 FilterQuery filter = new FilterQuery(follow);//?userID????? SiteStream.filter(filter);/*ww w. j a v a2 s.c om*/ }
From source file:Twitter.FilterStream.java
License:Apache License
public static void main(String[] args) throws TwitterException { System.getProperties().put("http.proxyHost", "127.0.0.1"); System.getProperties().put("http.proxyPort", "8580"); /* 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);//from w w w . j a v a 2 s.c om }*/ final FilterStream fs = new FilterStream(); try { fs.LinkMongodb(); } catch (Exception e) { e.printStackTrace(); } StatusListener listener = new StatusListener() { @Override public void onStatus(Status status) { System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText()); String str = DataObjectFactory.getRawJSON(status); try { //JSONObject nnstr = new JSONObject(newstr); DBObject dbObject = (DBObject) JSON.parse(str); fs.collection.insert(dbObject); //System.out.println(dbObject); fs.count++; if (fs.count > 900000000) { fs.mongo.close(); System.exit(0); } } catch (Exception e) { 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(); } }; ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("7ZVgfKiOvBDcDFpytRWSA") .setOAuthConsumerSecret("JmeJVeym78arzmGthrDUshQyhkq6nWA9tWLUKxc") .setOAuthAccessToken("321341780-Zy7LptVYBZBVvAeQ5GFJ4aKFw8sdqhWBnvA3pDuO") .setOAuthAccessTokenSecret("foi8FnQCeN0J5cdwad05Q6d7dbytFayQn1ZOvmhF6Qc"); cb.setJSONStoreEnabled(true); TwitterStreamFactory tf = new TwitterStreamFactory(cb.build()); TwitterStream twitterStream = tf.getInstance(); twitterStream.addListener(listener); ArrayList<Long> follow = new ArrayList<Long>(); ArrayList<String> track = new ArrayList<String>(); //String[] keywords = {"RT @justinbieber"}; String[] keywords = { "27260086" }; // user_id(justinbieber) for (String arg : keywords) { 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)); twitterStream.filter(new FilterQuery(followArray)); }
From source file:twitter4j.examples.lambda.TwitterStreamLambda.java
License:Apache License
public static void oldTraditionalDullBoringImplementation(String... dummy) { // Twitter4J 4.0.3 or earlier TwitterStream stream = TwitterStreamFactory.getSingleton(); stream.addListener(new StatusAdapter() { @Override/* ww w . j a v a 2 s .c o m*/ public void onStatus(Status status) { String.format("@%s %s", status.getUser().getScreenName(), status.getText()); } @Override public void onException(Exception ex) { ex.printStackTrace(); } }); stream.filter(new FilterQuery(new String[] { "twitter4j", "#twitter4j" })); }
From source file:user_streaming.UserStream.java
License:Apache License
public static void main(String[] args) throws Exception { Configuration configuration = new ConfigurationBuilder().setOAuthConsumerKey(CONSUMER_KEY) .setOAuthConsumerSecret(CONSUMER_SECRET).setOAuthAccessToken(ACCESS_TOKEN) .setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET) .setUserStreamBaseURL("https://userstream.twitter.com/2/").build(); TwitterStream UserStream = new TwitterStreamFactory(configuration).getInstance(); UserStream.addListener(new MyStreamAdapter()); long[] follow = { 1038644269 };//ex)????????anondroid3?id:1598997848 FilterQuery filter = new FilterQuery(follow);//?userID????? UserStream.filter(filter);/* ww w . j a v a2 s. co m*/ }