List of usage examples for twitter4j.conf ConfigurationBuilder ConfigurationBuilder
ConfigurationBuilder
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;//from w ww . j a v a2s . c om } 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:adapter.TwitterLocationAdapter.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;//from ww w.j a va 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) { } }; FilterQuery fq = new FilterQuery(); // Posiciones geogrficas, esas dos coordenadas son el vrtice superior izquierda e inferior derecho // de un rectangulo, de tal manera de analizar solo una parte geografica double position[][] = { { 0.0, 0.0 }, { 0.0, 0.0 } }; fq.locations(position); twitterStream.addListener(statusListener); twitterStream.filter(fq); }
From source file:alberapps.java.noticias.tw.tw4j.ProcesarTwitter4j.java
License:Open Source License
/** * Inicializar/*w w w . j ava 2 s.co m*/ */ public void setUp() { builder = new ConfigurationBuilder(); // builder.setUseSSL(true); builder.setApplicationOnlyAuthEnabled(true); try { twitter = new TwitterFactory(builder.build()).getInstance(); twitter.setOAuthConsumer(Constantes.ck, Constantes.cs); // Para que cargue OAuth2Token token = twitter.getOAuth2Token(); } catch (TwitterException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:algo.ad.feeder.TwitterStreamSpout.java
License:Apache License
@Override public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) { queue = new LinkedBlockingQueue<Status>(1000); _collector = collector;/*from w w w.ja v a2 s . c o m*/ startTime = System.currentTimeMillis(); StatusListener listener = new StatusListener() { @Override public void onStatus(Status status) { long elapsedTime = System.currentTimeMillis() - startTime; //System.out.println("*************elapsedTime:" + elapsedTime); if (elapsedTime > keywordRefreshInterval) { /// System.out.println("*************Changing Query:"); // Update the keyword list//////////////////// String[] temp_keywords = DatabaseHelper.getKeywordsFromDB(tweetsJDBCTemplate, DB_BASE_URL, DB_NAME, MAX_NUMBER_OF_QUERIES); if (!keyWords.equals(temp_keywords)) { keyWords = temp_keywords; FilterQuery query = new FilterQuery().track(keyWords); _twitterStream.filter(query); } // ///////////////////////////////////// startTime = System.currentTimeMillis(); } queue.offer(status); } @Override public void onDeletionNotice(StatusDeletionNotice sdn) { } @Override public void onTrackLimitationNotice(int i) { } @Override public void onScrubGeo(long l, long l1) { } @Override public void onException(Exception ex) { } @Override public void onStallWarning(StallWarning arg0) { // TODO Auto-generated method stub } }; _twitterStream = new TwitterStreamFactory(new ConfigurationBuilder().setJSONStoreEnabled(true).build()) .getInstance(); _twitterStream.addListener(listener); _twitterStream.setOAuthConsumer(consumerKey, consumerSecret); AccessToken token = new AccessToken(accessToken, accessTokenSecret); _twitterStream.setOAuthAccessToken(token); keyWords = DatabaseHelper.getKeywordsFromDB(tweetsJDBCTemplate, DB_BASE_URL, DB_NAME, MAX_NUMBER_OF_QUERIES); if (keyWords.length == 0) { _twitterStream.sample(); } else { FilterQuery query = new FilterQuery().track(keyWords); _twitterStream.filter(query); } }
From source file:android.stickynotes.StickyNotesActivity.java
License:Apache License
private void getTweets(String twit) { wifi.setWifiEnabled(true);/*from www . j a v a2s .c o m*/ ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("TvywVhWx7r7QQev2UGfA4g") .setOAuthConsumerSecret("Nv22zsyf1VS0vvi6hwAMyvJk9LUtSXwRUB4xwp2gRs"); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); try { QueryResult result = twitter.search(new Query(twit)); List<Tweet> tweets = result.getTweets(); textStatus.setText(""); textStatus.append("Recent tweets about '" + twit + "':\n"); for (Tweet tweet : tweets) { textStatus.append("@" + tweet.getFromUser() + " - " + tweet.getText() + "\n\n"); } } catch (TwitterException te) { te.printStackTrace(); textStatus.append("Failed to search tweets: " + te.getMessage() + " " + twit); } }
From source file:apptwitter.Metodos.java
public Metodos() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("5yqwH2WcqZ3YlkE0W8BLYkeoW") .setOAuthConsumerSecret("s5s5QGigqzULDGbbQs4Rm0pKdqLEefbO4gCh53XgcnA0RoMA9n") .setOAuthAccessToken("3055143533-jeaPEtFscvDMVKwPVLubxkmHs9DzCjZ2eIoWdcQ") .setOAuthAccessTokenSecret("NzIM687NlVRe3VxKh0a0xRRYpsGytrSEKISaqpuQGtTZL"); twitter = new TwitterFactory(cb.build()).getInstance(); }
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 av 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 . j a va 2s. c om 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.com.infiniterecursion.hashqanda.MainActivity.java
public boolean loadTweets() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("Q2DfeCNOxprbDp66fWlw") .setOAuthConsumerSecret("TgyJ26CKXz1SxGiEJx4HG9rytFsqiMZlEPeCO7S9g"); Twitter twitter = new TwitterFactory(cb.build()).getInstance(); // clear tweet list. MainActivity.this.runOnUiThread(new Runnable() { public void run() { // add to it , via the runOnUIThread app.getTweetList().clear();/*ww w. j av a 2 s. c om*/ } }); try { Log.d(TAG, " starting Tweets loading "); Query q = new Query("#qanda"); q.setRpp(numberTweets); QueryResult result = twitter.search(q); List<Tweet> tweets = result.getTweets(); for (Tweet tweet : tweets) { // Log.d(TAG, "@" + tweet.getFromUser() + " - " + // tweet.getText()); // Log.d(TAG, " img url " + tweet.getProfileImageUrl()); final CachedBitmapAndTweet cachedbmtwt = new CachedBitmapAndTweet(); cachedbmtwt.twt = tweet; try { URL url = new URL(tweet.getProfileImageUrl()); InputStream is = (InputStream) url.getContent(); if (is != null) { Bitmap bitmap = BitmapFactory.decodeStream(is); cachedbmtwt.bm = bitmap; } else { cachedbmtwt.bm = null; } } catch (MalformedURLException e) { e.printStackTrace(); cachedbmtwt.bm = null; } catch (IOException e) { e.printStackTrace(); cachedbmtwt.bm = null; } catch (NullPointerException npe) { npe.printStackTrace(); cachedbmtwt.bm = null; } MainActivity.this.runOnUiThread(new Runnable() { public void run() { // add to it , via the runOnUIThread app.getTweetList().add(cachedbmtwt); } }); } Log.d(TAG, " finished Tweets loading "); return true; } catch (TwitterException te) { te.printStackTrace(); Log.d(TAG, "Failed to search tweets: " + te.getMessage()); return false; } }
From source file:au.com.tyo.services.sn.twitter.SNTwitter.java
License:Apache License
public void createInstance() { synchronized (this) { try {// ww w .j ava 2 s .c o m if (hasSecret()) { AccessToken accessToken = new AccessToken(secretOAuth.getToken().getToken(), secretOAuth.getToken().getSecret()); Configuration conf = new ConfigurationBuilder().setOAuthConsumerKey(consumerKey) .setOAuthConsumerSecret(consumerKeySecret).setOAuthAccessToken(accessToken.getToken()) .setOAuthAccessTokenSecret(accessToken.getTokenSecret()).build(); OAuthAuthorization auth = new OAuthAuthorization(conf); twitter = new TwitterFactory().getInstance(auth); authenticated = true; } } catch (Exception ex) { authenticated = false; twitter = null; } try { /* * it is better to use the id, because people would change their name */ long sourceId = Integer.valueOf(secretOAuth.getId().getToken()); user = twitter.showUser(sourceId); // user = twitter.showUser(userInfo.getName()); secretOAuth.getId().setToken(String.valueOf(user.getId())); secrets.save(secretOAuth.getId()); userInfo.setName(user.getScreenName()); alias.setName(user.getName()); saveUserInfo(); saveAlias(); userProfileImageUrl = getUserAvatarUrl(); } catch (Exception ex) { } } }