List of usage examples for twitter4j FilterQuery FilterQuery
public FilterQuery(int count, long[] follow, String[] track, double[][] locations)
From source file:ar.com.zauber.commons.social.twitter.impl.streaming.TweetFetcher.java
License:Apache License
/** * Transforms a {@link TwitterFilter} to a {@link FilterQuery} * /*www.j av a2 s . co m*/ * @param filter2 * the {@link TwitterFilter} * @return the {@link FilterQuery} */ private FilterQuery toFilterQuery(final StreamingFilter filter2) { final int count = filter2.getPreviousStatuses(); final long[] follow = filter2.getUserIds(); final String[] track = filter2.getKeywords(); double[][] locations; final BoundingBox[] boxes = filter2.getBoxes(); if (boxes != null) { locations = new double[boxes.length * 2][2]; for (int i = 0; i < boxes.length; i += 2) { BoundingBox box = boxes[i]; locations[i][0] = box.getSwLong(); locations[i][1] = box.getSwLat(); locations[i + 1][0] = box.getNeLong(); locations[i + 1][1] = box.getNeLat(); } } else { locations = new double[][] {}; } return new FilterQuery(count, follow, track, locations); }
From source file:de.jetwick.tw.NewClass.java
License:Apache License
/** * A thread using the streaming API./*from w ww .j a v a 2s. c o m*/ * Maximum tweets/sec == 50 !! we'll lose even infrequent tweets for a lot keywords! */ public Thread streaming(final String token, final String tokenSecret) { return new Thread() { StatusListener listener = new StatusListener() { int counter = 0; public void onStatus(Status status) { if (++counter % 20 == 0) log("async counter=" + counter); asyncMap.put(status.getId(), status.getText()); } public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { log("Got a status deletion notice id:" + statusDeletionNotice.getStatusId()); } public void onTrackLimitationNotice(int numberOfLimitedStatuses) { log("Got track limitation notice:" + numberOfLimitedStatuses); } public void onScrubGeo(int userId, long upToStatusId) { log("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId); } public void onException(Exception ex) { ex.printStackTrace(); } }; public void run() { TwitterStream twitterStream = new TwitterStreamFactory() .getInstance(new AccessToken(token, tokenSecret)); twitterStream.addListener(listener); twitterStream.filter(new FilterQuery(0, null, new String[] { queryTerms }, null)); } }; }
From source file:socialImport.twitter.TwitterImport.java
License:Open Source License
@Override public void openFilterStream(StreamDescriptor streamDescriptor, int count, long[] follow, double[][] locations) { //If the stream ID is not in use yet if (!streams.keySet().contains(streamDescriptor)) { TwitterStream twitterStream = twitterStreamFactory.getInstance(); twitterStream.addListener(new TweetToDatabaseImportListener(streamDescriptor, dataModule)); FilterQuery filterQuery = new FilterQuery(count, follow, streamDescriptor.getTrackedTags(), locations); streams.put(streamDescriptor, twitterStream); twitterStream.filter(filterQuery); } else// w ww . j a va 2s.c o m throw new IllegalArgumentException(DUPLICATE_ID_ERROR_MESSAGE); }