List of usage examples for twitter4j.conf ConfigurationBuilder build
public Configuration build()
From source file:onl.area51.a51li.twitter.TwitterAccount.java
License:Apache License
public TwitterAccount(int id, String account, String token, String secret, TwitterApplication application) { this.id = id; this.account = account; this.token = token; this.secret = secret; ConfigurationBuilder cb = new ConfigurationBuilder().setOAuthConsumerKey(application.getKey()) .setOAuthConsumerSecret(application.getSecret()).setOAuthAccessToken(token) .setOAuthAccessTokenSecret(secret); TwitterFactory f = new TwitterFactory(cb.build()); twitter = f.getInstance();/*from w ww. j a v a2 s.co m*/ }
From source file:ontoSentiment.Amigos.java
@Override public void run() { ConfigurationBuilder cb = new ConfigurationBuilder(); //the following is set without accesstoken- desktop client cb.setDebugEnabled(true).setOAuthConsumerKey("FBd5n7dyl8mCz73qyfZ0p4XHb") .setOAuthConsumerSecret("vu5Xt5TzBSL9naOZylIYlx5MdcRlhH2LvkpW6KIkxSf9AqwuGt") .setOAuthAccessToken("3232400175-lAchtC6ChWMTnJKe3BaWbst8SucIaTjn5gm4Rp2") .setOAuthAccessTokenSecret("DnkquBWAS6igYpM8Z4r54hH7ztcfMX6u8OzMXBLwM9Xkh"); try {/* ww w . j av a 2s. c om*/ TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); //User u = twitter.showUser("karlaffabiola"); User u = twitter.showUser("raythemaster"); IDs ids; System.out.println("Listing followers's ids."); System.out.println("ID: " + u.getId()); System.out.println("Nome: " + u.getScreenName()); long cursor = -1; PagableResponseList<User> pagableFollowings; List<User> listFriends = new ArrayList<>(); List<User> listFriends2 = new ArrayList<>(); pagableFollowings = twitter.getFriendsList(u.getId(), cursor, 200); System.out.println("Qunatidade followers: " + pagableFollowings.size()); for (User user : pagableFollowings) { System.out.println("Id: " + user.getId() + " Nome: " + user.getScreenName()); listFriends.add(user); // ArrayList<User> } for (User user : listFriends) { System.out.println("Id1: " + user.getId() + " Nome1: " + user.getScreenName()); pagableFollowings = twitter.getFriendsList(user.getId(), cursor, 200); System.out.println("Qunatidade followers: " + pagableFollowings.size()); for (User user2 : pagableFollowings) { System.out.println("Id2: " + user2.getId() + " Nome2: " + user2.getScreenName()); listFriends2.add(user2); // ArrayList<User> } } System.out.println("Lista 1:" + listFriends.size()); System.out.println("Lista 2:" + listFriends2.size()); System.exit(0); } catch (TwitterException te) { // te.printStackTrace(); System.out.println("Failed to get timeline: " + new Date()); try { Thread.sleep(3 * 60 * 1000); run(); } catch (InterruptedException ex) { Logger.getLogger(Amigos.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:ontoSentiment.Util.java
public static OAuth2Token getOAuth2Token() { OAuth2Token token = null;//from w w w . jav a2 s . c o m 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:ontoSentiment.Util.java
public static Twitter getTwitter() { OAuth2Token token;//from w w w.j ava2s . c om 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:org.addhen.smssync.data.twitter.TwitterClient.java
License:Open Source License
private void initTwitterFactory() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(mAuthConfig.consumerKey); builder.setOAuthConsumerSecret(mAuthConfig.consumerSecret); mTwitterFactory = new TwitterFactory(builder.build()); }
From source file:org.apache.apex.malhar.contrib.twitter.TwitterSampleInput.java
License:Apache License
@Override public void setup(OperatorContext context) { operatorThread = Thread.currentThread(); if (feedMultiplier != 1) { logger.info("Load set to be {}% of the entire twitter feed", feedMultiplier); }//from www .j a v a 2 s . co m ConfigurationBuilder cb = setupConfigurationBuilder(); ts = new TwitterStreamFactory(cb.build()).getInstance(); }
From source file:org.apache.apex.malhar.contrib.twitter.TwitterSampleInput.java
License:Apache License
private void setUpTwitterConnection() { ConfigurationBuilder cb = setupConfigurationBuilder(); ts = new TwitterStreamFactory(cb.build()).getInstance(); ts.addListener(TwitterSampleInput.this); // we can only listen to tweets containing links by callng ts.links(). // it seems it requires prior signed agreement with twitter. ts.sample();//from ww w . jav a2 s . c o m }
From source file:org.apache.asterix.external.util.TwitterUtil.java
License:Apache License
public static Twitter getTwitterService(Map<String, String> configuration) { ConfigurationBuilder cb = getAuthConfiguration(configuration); TwitterFactory tf = null;/* w w w.j a v a 2 s. c om*/ try { tf = new TwitterFactory(cb.build()); } catch (Exception e) { if (LOGGER.isLoggable(Level.WARNING)) { StringBuilder builder = new StringBuilder(); builder.append("Twitter Adapter requires the following config parameters\n"); builder.append(AuthenticationConstants.OAUTH_CONSUMER_KEY + "\n"); builder.append(AuthenticationConstants.OAUTH_CONSUMER_SECRET + "\n"); builder.append(AuthenticationConstants.OAUTH_ACCESS_TOKEN + "\n"); builder.append(AuthenticationConstants.OAUTH_ACCESS_TOKEN_SECRET + "\n"); LOGGER.warning(builder.toString()); LOGGER.warning( "Unable to configure Twitter adapter due to incomplete/incorrect authentication credentials"); LOGGER.warning( "For details on how to obtain OAuth authentication token, visit https://dev.twitter.com/oauth/overview/application-owner-access-tokens"); } } Twitter twitter = tf.getInstance(); return twitter; }
From source file:org.apache.camel.component.twitter.TwitterConfiguration.java
License:Apache License
/** * Builds a Twitter4J Configuration using the OAuth params. * * @return Configuration//from w w w . ja va2 s . c o m */ public Configuration getConfiguration() { checkComplete(); ConfigurationBuilder confBuilder = new ConfigurationBuilder(); confBuilder.setOAuthConsumerKey(consumerKey); confBuilder.setOAuthConsumerSecret(consumerSecret); confBuilder.setOAuthAccessToken(accessToken); confBuilder.setOAuthAccessTokenSecret(accessTokenSecret); confBuilder.setUseSSL(useSSL); if (getHttpProxyHost() != null) { confBuilder.setHttpProxyHost(getHttpProxyHost()); } if (getHttpProxyUser() != null) { confBuilder.setHttpProxyHost(getHttpProxyUser()); } if (getHttpProxyPassword() != null) { confBuilder.setHttpProxyHost(getHttpProxyPassword()); } if (httpProxyPort != null) { confBuilder.setHttpProxyPort(httpProxyPort); } return confBuilder.build(); }
From source file:org.apache.nutch.protocol.http.api.HttpBase.java
License:Apache License
private TwitterFactory getTwitterFactoryWithConfigParams(String consumerKey, String consumerSecret, String accessToken, String accessTokenSecret) { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret) .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessTokenSecret) .setPrettyDebugEnabled(true); TwitterFactory tf = new TwitterFactory(cb.build()); return tf;//from w w w . j a va 2 s. com }