List of usage examples for twitter4j FilterQuery track
String[] track
To view the source code for twitter4j FilterQuery track.
Click Source Link
From source file:Read_data.java
/** * @param args the command line arguments * @throws twitter4j.TwitterException//from w ww .j a v a 2s .c om * @throws java.io.FileNotFoundException */ public static void main(String[] args) throws TwitterException, FileNotFoundException, IOException { // TODO code application logic here ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(customer_key).setOAuthConsumerSecret(customer_secret) .setOAuthAccessToken(access_token).setOAuthAccessTokenSecret(access_token_secret); TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); StatusListener statusListener = new StatusListener() { @Override public void onStatus(Status status) { //get the place if it is not null if (status.getPlace() != null) { try { String place = status.getPlace().getName(); System.out.println("Place: " + place + "\t\t\t" + "Tweet: " + status.getText()); Thread.sleep(1000); } catch (InterruptedException ex) { Logger.getLogger(Read_data.class.getName()).log(Level.SEVERE, null, ex); } } } @Override public void onDeletionNotice(StatusDeletionNotice sdn) { System.out.print(""); } @Override public void onTrackLimitationNotice(int i) { System.out.print(""); } @Override public void onScrubGeo(long l, long l1) { System.out.print(""); } @Override public void onStallWarning(StallWarning sw) { System.out.println(sw); } @Override public void onException(Exception ex) { System.out.println(ex); } }; FilterQuery fq = new FilterQuery(); //Stream tweets with these keywords. Replace for your tweets that you are looking for. String keywords[] = { "lol", "lls", "lmao", "llf" }; fq.track(keywords); twitterStream.addListener(statusListener); twitterStream.filter(fq); try { synchronized (lock) { lock.wait(); } } catch (InterruptedException e) { System.out.println(e); } System.out.println("returning statuses"); // twitterStream.shutdown(); }
From source file:TwitterListenerSnippet.java
License:BEER-WARE LICENSE
public void setupListener(Configuration c) { filtreListener = "love"; TwitterStream ts = new TwitterStreamFactory(c).getInstance(); FilterQuery filterQuery = new FilterQuery(); filterQuery.track(new String[] { filtreListener }); // On fait le lien entre le TwitterStream (qui r\u00e9cup\u00e8re les messages) et notre \u00e9couteur ts.addListener(new TwitterListener()); // On d\u00e9marre la recherche ! ts.filter(filterQuery);/*from www. ja va 2s . c o m*/ }
From source file:adapter.TwitterKeywordsAdapter.java
License:Apache License
public void connectAndRead() throws Exception { ConfigurationBuilder cb = new ConfigurationBuilder(); Properties twitterProperties = new Properties(); File twitter4jPropsFile = new File("../twitter4j.properties"); if (!twitter4jPropsFile.exists()) { logger.error("Cannot find twitter4j.properties file in this location :[{}]", twitter4jPropsFile.getAbsolutePath()); return;/* w w w . j a va 2s. co m*/ } twitterProperties.load(new FileInputStream(twitter4jPropsFile)); cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey(twitterProperties.getProperty("oauth.consumerKey")); cb.setOAuthConsumerSecret(twitterProperties.getProperty("oauth.consumerSecret")); cb.setOAuthAccessToken(twitterProperties.getProperty("oauth.accessToken")); cb.setOAuthAccessTokenSecret(twitterProperties.getProperty("oauth.accessTokenSecret")); cb.setDebugEnabled(false); cb.setPrettyDebugEnabled(false); cb.setIncludeMyRetweetEnabled(false); TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); StatusListener statusListener = new StatusListener() { @Override public void onException(Exception ex) { } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { } @Override public void onStatus(Status status) { messageQueue.add(status); } @Override public void onScrubGeo(long userId, long upToStatusId) { } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { } @Override public void onStallWarning(StallWarning arg0) { } }; FilterQuery fq = new FilterQuery(); //System.out.println(Arrays.toString(configuration.getTrack())); //Elige todos los tweets que posean esas palabras claves fq.track(new String[] { "palabra1,palabra2,palabra3" }); //fq.track(keywords); twitterStream.addListener(statusListener); twitterStream.filter(fq); }
From source file:adapter.TwitterLanguageAdapter.java
License:Apache License
public void connectAndRead() throws Exception { ConfigurationBuilder cb = new ConfigurationBuilder(); Properties twitterProperties = new Properties(); File twitter4jPropsFile = new File("../twitter4j.properties"); if (!twitter4jPropsFile.exists()) { logger.error("Cannot find twitter4j.properties file in this location :[{}]", twitter4jPropsFile.getAbsolutePath()); return;// w w w .jav a 2 s .c o m } twitterProperties.load(new FileInputStream(twitter4jPropsFile)); cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey(twitterProperties.getProperty("oauth.consumerKey")); cb.setOAuthConsumerSecret(twitterProperties.getProperty("oauth.consumerSecret")); cb.setOAuthAccessToken(twitterProperties.getProperty("oauth.accessToken")); cb.setOAuthAccessTokenSecret(twitterProperties.getProperty("oauth.accessTokenSecret")); cb.setDebugEnabled(false); cb.setPrettyDebugEnabled(false); cb.setIncludeMyRetweetEnabled(false); TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); StatusListener statusListener = new StatusListener() { @Override public void onException(Exception ex) { } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { } @Override public void onStatus(Status status) { messageQueue.add(status); } @Override public void onScrubGeo(long userId, long upToStatusId) { } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { } @Override public void onStallWarning(StallWarning arg0) { } }; //Filter language and track FilterQuery tweetFilterQuery = new FilterQuery(); tweetFilterQuery.track(new String[] { "palabra1,palabra2,palabra3" }); tweetFilterQuery.language(new String[] { "es" }); //TwitterStream twitterStream.addListener(statusListener); twitterStream.filter(tweetFilterQuery); }
From source file:at.aictopic1.twitter.AICStream.java
private FilterQuery getQuery() { FilterQuery query = new FilterQuery(); String[] track = this.track.toArray(new String[this.track.size()]); query.track(track); String[] lang = this.lang.toArray(new String[this.lang.size()]); query.language(lang);//w w w. j av a 2 s. c om return query; }
From source file:at.illecker.sentistorm.spout.TwitterStreamSpout.java
License:Apache License
@Override public void open(Map config, TopologyContext context, SpoutOutputCollector collector) { m_collector = collector;/*from ww w.j a v a 2 s. co m*/ m_tweetsQueue = new LinkedBlockingQueue<Status>(1000); // Optional startup sleep to finish bolt preparation // before spout starts emitting if (config.get(CONF_STARTUP_SLEEP_MS) != null) { long startupSleepMillis = (Long) config.get(CONF_STARTUP_SLEEP_MS); TimeUtils.sleepMillis(startupSleepMillis); } TwitterStream twitterStream = new TwitterStreamFactory( new ConfigurationBuilder().setJSONStoreEnabled(true).build()).getInstance(); // Set Listener twitterStream.addListener(new StatusListener() { @Override public void onStatus(Status status) { m_tweetsQueue.offer(status); // add tweet into queue } @Override public void onException(Exception arg0) { } @Override public void onDeletionNotice(StatusDeletionNotice arg0) { } @Override public void onScrubGeo(long arg0, long arg1) { } @Override public void onStallWarning(StallWarning arg0) { } @Override public void onTrackLimitationNotice(int arg0) { } }); // Set credentials twitterStream.setOAuthConsumer(m_consumerKey, m_consumerSecret); AccessToken token = new AccessToken(m_accessToken, m_accessTokenSecret); twitterStream.setOAuthAccessToken(token); // Filter twitter stream FilterQuery tweetFilterQuery = new FilterQuery(); if (m_keyWords != null) { tweetFilterQuery.track(m_keyWords); } // Filter location // https://dev.twitter.com/docs/streaming-apis/parameters#locations tweetFilterQuery.locations(new double[][] { new double[] { -180, -90, }, new double[] { 180, 90 } }); // any geotagged tweet // Filter language tweetFilterQuery.language(new String[] { m_filterLanguage }); twitterStream.filter(tweetFilterQuery); }
From source file:at.storm.spout.TwitterStreamSpout.java
License:Apache License
@SuppressWarnings("rawtypes") @Override//from w w w.ja va 2 s. c o m public void open(Map config, TopologyContext context, SpoutOutputCollector collector) { m_collector = collector; m_tweetsQueue = new LinkedBlockingQueue<Status>(1000); // Optional startup sleep to finish bolt preparation // before spout starts emitting if (config.get(CONF_STARTUP_SLEEP_MS) != null) { long startupSleepMillis = (Long) config.get(CONF_STARTUP_SLEEP_MS); TimeUtils.sleepMillis(startupSleepMillis); } TwitterStream twitterStream = new TwitterStreamFactory( new ConfigurationBuilder().setJSONStoreEnabled(true).build()).getInstance(); // Set Listener twitterStream.addListener(new StatusListener() { @Override public void onStatus(Status status) { m_tweetsQueue.offer(status); // add tweet into queue } @Override public void onException(Exception arg0) { } @Override public void onDeletionNotice(StatusDeletionNotice arg0) { } @Override public void onScrubGeo(long arg0, long arg1) { } @Override public void onStallWarning(StallWarning arg0) { } @Override public void onTrackLimitationNotice(int arg0) { } }); // Set credentials twitterStream.setOAuthConsumer(m_consumerKey, m_consumerSecret); AccessToken token = new AccessToken(m_accessToken, m_accessTokenSecret); twitterStream.setOAuthAccessToken(token); // Filter twitter stream FilterQuery tweetFilterQuery = new FilterQuery(); if (m_keyWords != null) { tweetFilterQuery.track(m_keyWords); } // Filter location // https://dev.twitter.com/docs/streaming-apis/parameters#locations tweetFilterQuery.locations(new double[][] { new double[] { -180, -90, }, new double[] { 180, 90 } }); // any // geotagged // tweet // Filter language tweetFilterQuery.language(new String[] { m_filterLanguage }); twitterStream.filter(tweetFilterQuery); }
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.// www . j av a2 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:birdseye.Sample.java
License:Apache License
public List<TweetData> execute(String[] args) throws TwitterException { final List<TweetData> statuses = new ArrayList(); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthAccessToken("14538839-3MX2UoCEUaA6u95iWoYweTKRbhBjqEVuK1SPbCjDV"); cb.setOAuthAccessTokenSecret("nox7eYyOJpyiDiISHRDou90bGkHKasuw1IMqqJUZMaAbj"); TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); StatusListener listener = new StatusListener() { public void onStatus(Status status) { String user = status.getUser().getScreenName(); String content = status.getText(); TweetData newTweet = new TweetData(user, content); statuses.add(newTweet);//from w w w . j a v a 2s .c om System.out.println(statuses.size() + ":" + status.getText()); if (statuses.size() > 15) { synchronized (lock) { lock.notify(); } System.out.println("unlocked"); } } 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(); } @Override public void onStallWarning(StallWarning sw) { System.out.println(sw.getMessage()); } }; FilterQuery fq = new FilterQuery(); String[] keywords = args; fq.track(keywords); twitterStream.addListener(listener); twitterStream.filter(fq); try { synchronized (lock) { lock.wait(); } } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("returning statuses"); twitterStream.shutdown(); return statuses; }
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 ww.j a va 2 s . c o m*/ if (data.getHashTags() != null) { fq.track(data.getHashTags()); } twitterStream.filter(fq); } else { twitterStream.firehose(1000); } }