List of usage examples for twitter4j.conf ConfigurationBuilder setOAuthAccessToken
public ConfigurationBuilder setOAuthAccessToken(String oAuthAccessToken)
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;/*from w w w .jav a 2s . com*/ } 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 ww. j ava 2 s .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) { } }; //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 w w 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:benche.me.TwitterParser.Main.java
License:Open Source License
/** * Configure twitter API connection for tweet streaming * @return TwitterStream instance//from www. ja va2s . c o m */ private static TwitterStream configureStream() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey(Constants.CONSUMER_KEY_KEY); cb.setOAuthConsumerSecret(Constants.CONSUMER_SECRET_KEY); cb.setOAuthAccessToken(Constants.ACCESS_TOKEN_KEY); cb.setOAuthAccessTokenSecret(Constants.ACCESS_TOKEN_SECRET_KEY); cb.setJSONStoreEnabled(true); cb.setIncludeEntitiesEnabled(true); return new TwitterStreamFactory(cb.build()).getInstance(); }
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 ww .j a va 2 s. 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:com.ak.android.akplaza.common.sns.twitter.TwitterController.java
License:Open Source License
public static void write(String content, Activity at) { // Log.d(TAG, "content : " + content); String path = Environment.getExternalStorageDirectory().getAbsolutePath(); String fileName = "example.jpg"; InputStream is = null;/*from w w w. j av a 2s . c om*/ try { if (new File(path + File.separator + fileName).exists()) is = new FileInputStream(path + File.separator + fileName); else is = null; ConfigurationBuilder cb = new ConfigurationBuilder(); String oAuthAccessToken = acToken.getToken(); String oAuthAccessTokenSecret = tacs; String oAuthConsumerKey = C.TWITTER_CONSUMER_KEY; String oAuthConsumerSecret = C.TWITTER_CONSUMER_SECRET; cb.setOAuthAccessToken(oAuthAccessToken); cb.setOAuthAccessTokenSecret(oAuthAccessTokenSecret); cb.setOAuthConsumerKey(oAuthConsumerKey); cb.setOAuthConsumerSecret(oAuthConsumerSecret); Configuration config = cb.build(); OAuthAuthorization auth = new OAuthAuthorization(config); TwitterFactory tFactory = new TwitterFactory(config); Twitter twitter = tFactory.getInstance(); // ImageUploadFactory iFactory = new ImageUploadFactory(getConfiguration(C.TWITPIC_API_KEY)); // ImageUpload upload = iFactory.getInstance(MediaProvider.TWITPIC, auth); if (is != null) { // String strResult = upload.upload("example.jpg", is, mEtContent.getText().toString()); // twitter.updateStatus(mEtContent.getText().toString() + " " + strResult); } else twitter.updateStatus(content); new AlertDialog.Builder(at).setMessage(" ? ? ?.") .setPositiveButton("?", null).show(); } catch (Exception e) { e.printStackTrace(); new AlertDialog.Builder(at).setMessage("? ? ") .setPositiveButton("?", null).show(); } finally { try { is.close(); } catch (Exception e) { } } }
From source file:com.babatunde.twittergoogle.Utility.java
public Utility() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(""); builder.setOAuthConsumerSecret(""); builder.setOAuthAccessToken(""); builder.setOAuthAccessTokenSecret(""); configuration = builder.build();/*from ww w . jav a2s.co m*/ }
From source file:com.cloudera.flume.source.TwitterSource.java
License:Apache License
/** * The initialization method for the Source. The context contains all the * Flume configuration info, and can be used to retrieve any configuration * values necessary to set up the Source. *//*from w w w .j ava2s . c o m*/ @Override public void configure(Context context) { consumerKey = context.getString(TwitterSourceConstants.CONSUMER_KEY_KEY); consumerSecret = context.getString(TwitterSourceConstants.CONSUMER_SECRET_KEY); accessToken = context.getString(TwitterSourceConstants.ACCESS_TOKEN_KEY); accessTokenSecret = context.getString(TwitterSourceConstants.ACCESS_TOKEN_SECRET_KEY); String keywordString = context.getString(TwitterSourceConstants.KEYWORDS_KEY, ""); keywords = keywordString.split(","); for (int i = 0; i < keywords.length; i++) { keywords[i] = keywords[i].trim(); } ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey(consumerKey); cb.setOAuthConsumerSecret(consumerSecret); cb.setOAuthAccessToken(accessToken); cb.setOAuthAccessTokenSecret(accessTokenSecret); cb.setJSONStoreEnabled(true); cb.setIncludeEntitiesEnabled(true); twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); }
From source file:com.daemon.TwitterProfile.java
License:Open Source License
public TwitterProfile(String name, String screenName, String consumerKey, String consumerSecret, String accessToken, String accessTokenSecret, DaemonProperties properties) { _profileName = name;/*www .j av a 2s . com*/ _screenName = screenName; _consumerKey = consumerKey; _consumerSecret = consumerSecret; _accessToken = accessToken; _accessTokenSecret = accessTokenSecret; _props = properties; // Create Twitter object ConfigurationBuilder conf = new ConfigurationBuilder(); conf.setOAuthAccessToken(getAccessToken()).setOAuthAccessTokenSecret(getAccessTokenSecret()) .setOAuthConsumerKey(getConsumerKey()).setOAuthConsumerSecret(getConsumerSecret()); _twitter = new TwitterFactory(conf.build()).getInstance(); }
From source file:com.esri.geoevent.transport.twitter.TwitterInboundTransport.java
License:Apache License
private void receiveData() { try {/*w w w . ja v a2s.c o m*/ applyProperties(); setRunningState(RunningState.STARTED); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true); cb.setOAuthConsumerKey(consumerKey); cb.setOAuthConsumerSecret(consumerSecret); cb.setOAuthAccessToken(accessToken); cb.setOAuthAccessTokenSecret(accessTokenSecret); twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); RawStreamListener rl = new RawStreamListener() { @Override public void onException(Exception ex) { LOGGER.error("INBOUND_TRANSPORT_RAW_STREAM_LISTERNER_EXCEPTION", ex.getMessage()); } @Override public void onMessage(String rawString) { receive(rawString); } }; FilterQuery fq = new FilterQuery(); String keywords[] = tracks; if (follows != null && follows.length > 0) fq.follow(follows); else if (keywords != null && keywords.length > 0) fq.track(keywords); else if (locations != null) fq.locations(locations); else throw new Exception("INBOUND_TRANSPORT_NOFILTER_ERROR"); fq.count(count); LOGGER.info("INBOUND_TRANSPORT_FILTER", filterString); twitterStream.addListener(rl); twitterStream.filter(fq); } catch (Throwable ex) { LOGGER.error("UNEXPECTED_ERROR", ex); setRunningState(RunningState.ERROR); } }