List of usage examples for twitter4j.conf ConfigurationBuilder build
public Configuration build()
From source file:benche.me.TwitterParser.Main.java
License:Open Source License
/** * Configure twitter API connection for historical search * @return Twitter connection instance *///from w ww.j a v a 2 s .c o m private static Twitter configureSearch() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(Constants.CONSUMER_KEY_KEY) .setOAuthConsumerSecret(Constants.CONSUMER_SECRET_KEY) .setOAuthAccessToken(Constants.ACCESS_TOKEN_KEY) .setOAuthAccessTokenSecret(Constants.ACCESS_TOKEN_SECRET_KEY); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); return twitter; }
From source file:benche.me.TwitterParser.Main.java
License:Open Source License
/** * Configure twitter API connection for tweet streaming * @return TwitterStream instance/*from w w w . ja v a 2 s . 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 w w . j av a 2 s . co m 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.controller.TweetController.java
public static OAuth2Token getOAuth2Token() { OAuth2Token token = null;//from w w w . j av a 2s . c om ConfigurationBuilder cb; cb = new ConfigurationBuilder(); cb.setApplicationOnlyAuthEnabled(true); cb.setOAuthConsumerKey(CONSUMER_KEY).setOAuthConsumerSecret(CONSUMER_SECRET); try { token = new TwitterFactory(cb.build()).getInstance().getOAuth2Token(); } catch (Exception e) { System.out.println("Could not get OAuth2 token"); e.printStackTrace(); System.exit(0); } return token; }
From source file:br.com.controller.TweetController.java
public static Twitter getTwitter() { OAuth2Token token;/*w ww . j av a 2s .c o m*/ token = getOAuth2Token(); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setApplicationOnlyAuthEnabled(true); cb.setOAuthConsumerKey(CONSUMER_KEY); cb.setOAuthConsumerSecret(CONSUMER_SECRET); cb.setOAuth2TokenType(token.getTokenType()); cb.setOAuth2AccessToken(token.getAccessToken()); return new TwitterFactory(cb.build()).getInstance(); }
From source file:clientetwitter.ClienteTwitter.java
public static void PostInTimeLine(String texto) throws TwitterException { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("xxxxxxxxxxxx") //to get all the OAuth go to apps.twitter.com .setOAuthConsumerSecret("xxxxxxxxxxxxxxxx").setOAuthAccessToken("xxxxxxxxxxxxxxxxxxxxxxx") .setOAuthAccessTokenSecret("xxxxxxxxxxxxxxxxxxxx"); TwitterFactory tf = new TwitterFactory(cb.build()); twitter4j.Twitter tw = tf.getInstance(); //posting// www . j a va 2 s . com Status stat = tw.updateStatus(texto); System.out.println("Posted"); }
From source file:clientetwitter.ClienteTwitter.java
public static void ReadTimeLine() throws TwitterException { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("ZpF1TSpAyQlBLMN7egUz3uT3D") .setOAuthConsumerSecret("r2icg36QB6G862Re2IvwHNGuDK25z5awKSeNG9kV9LRpcAmuOW") .setOAuthAccessToken("4314010284-QGXKFbFQ5TK4zqbplRsfoP0wL6NTv7bsMJypWex") .setOAuthAccessTokenSecret("4v61YXTkzM3Kob0xAHu59ISgM0fTKSLrOuDXTG5ctX7rr"); TwitterFactory tf = new TwitterFactory(cb.build()); twitter4j.Twitter tw = tf.getInstance(); //reading//from w w w .j av a 2 s . co m List<Status> statuses = tw.getHomeTimeline(); for (Status status1 : statuses) { System.out.println(status1.getUser().getName() + ": " + status1.getText()); } }
From source file:cloudcomputebot.Twitter.TwitterLib.java
License:Open Source License
public static void init() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("yZpAVykzcxwyohWOVBwuFaaaB") .setOAuthConsumerSecret("tXZQzYPeh1YmxGUPYotaKFoeLKeI6m8dAPgPh60l4mSltmMpxw") .setOAuthAccessToken("4741197613-i0WRUBMg1oGM2JR6GWnAztKs60u8lhMBhlr8TXD") .setOAuthAccessTokenSecret("H4EMPCNPV0NkTom3aUZB8J2uOaWnYHC28vxyTZ1bCvpd6"); TwitterFactory tf = new TwitterFactory(cb.build()); t = tf.getInstance();//from w w w.java2 s.co m }
From source file:co.cask.cdap.template.etl.realtime.source.TwitterSource.java
License:Apache License
@Override public void initialize(RealtimeContext context) throws Exception { super.initialize(context); // Disable chatty logging from twitter4j. System.setProperty("twitter4j.loggerFactory", "twitter4j.NullLoggerFactory"); Schema.Field idField = Schema.Field.of(ID, Schema.of(Schema.Type.LONG)); Schema.Field msgField = Schema.Field.of(MSG, Schema.of(Schema.Type.STRING)); Schema.Field langField = Schema.Field.of(LANG, Schema.nullableOf(Schema.of(Schema.Type.STRING))); Schema.Field timeField = Schema.Field.of(TIME, Schema.nullableOf(Schema.of(Schema.Type.LONG))); Schema.Field favCount = Schema.Field.of(FAVC, Schema.of(Schema.Type.INT)); Schema.Field rtCount = Schema.Field.of(RTC, Schema.of(Schema.Type.INT)); Schema.Field sourceField = Schema.Field.of(SRC, Schema.nullableOf(Schema.of(Schema.Type.STRING))); Schema.Field geoLatField = Schema.Field.of(GLAT, Schema.nullableOf(Schema.of(Schema.Type.DOUBLE))); Schema.Field geoLongField = Schema.Field.of(GLNG, Schema.nullableOf(Schema.of(Schema.Type.DOUBLE))); Schema.Field reTweetField = Schema.Field.of(ISRT, Schema.of(Schema.Type.BOOLEAN)); schema = Schema.recordOf("tweet", idField, msgField, langField, timeField, favCount, rtCount, sourceField, geoLatField, geoLongField, reTweetField); statusListener = new StatusListener() { @Override/* w ww . ja v a 2 s. c o m*/ public void onStatus(Status status) { tweetQ.add(status); } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { // No-op } @Override public void onTrackLimitationNotice(int i) { // No-op } @Override public void onScrubGeo(long l, long l1) { // No-op } @Override public void onStallWarning(StallWarning stallWarning) { // No-op } @Override public void onException(Exception e) { // No-op } }; ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setDebugEnabled(false).setOAuthConsumerKey(twitterConfig.consumerKey) .setOAuthConsumerSecret(twitterConfig.consumeSecret).setOAuthAccessToken(twitterConfig.accessToken) .setOAuthAccessTokenSecret(twitterConfig.accessTokenSecret); twitterStream = new TwitterStreamFactory(configurationBuilder.build()).getInstance(); twitterStream.addListener(statusListener); twitterStream.sample(); }
From source file:co.cask.hydrator.plugin.realtime.source.TwitterSource.java
License:Apache License
@Override public void initialize(RealtimeContext context) throws Exception { super.initialize(context); // Disable chatty logging from twitter4j. System.setProperty("twitter4j.loggerFactory", "twitter4j.NullLoggerFactory"); statusListener = new StatusListener() { @Override//from w ww . j av a2s .co m public void onStatus(Status status) { tweetQ.add(status); } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { // No-op } @Override public void onTrackLimitationNotice(int i) { // No-op } @Override public void onScrubGeo(long l, long l1) { // No-op } @Override public void onStallWarning(StallWarning stallWarning) { // No-op } @Override public void onException(Exception e) { // No-op } }; ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setDebugEnabled(false).setOAuthConsumerKey(twitterConfig.consumerKey) .setOAuthConsumerSecret(twitterConfig.consumeSecret).setOAuthAccessToken(twitterConfig.accessToken) .setOAuthAccessTokenSecret(twitterConfig.accessTokenSecret); twitterStream = new TwitterStreamFactory(configurationBuilder.build()).getInstance(); twitterStream.addListener(statusListener); twitterStream.sample(); }