List of usage examples for twitter4j.conf ConfigurationBuilder ConfigurationBuilder
ConfigurationBuilder
From source file:org.mule.twitter.TwitterConnector.java
License:Open Source License
/** * Connects to Twitter/*from w w w .j a va 2 s . c om*/ * @param accessKey The access key provided by Twitter * @param accessSecret The access secret provided by Twitter * @throws ConnectionException when the connection fails */ @Connect public void connect(@ConnectionKey String accessKey, String accessSecret) throws ConnectionException { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setUseSSL(useSSL); cb.setHttpProxyHost(proxyHost); cb.setHttpProxyPort(proxyPort); cb.setHttpProxyUser(proxyUsername); cb.setHttpProxyPassword(proxyPassword); HttpClientHiddenConstructionArgument.setUseMule(true); twitter = new TwitterFactory(cb.build()).getInstance(); twitter.setOAuthConsumer(consumerKey, consumerSecret); if (accessKey != null) { twitter.setOAuthAccessToken(new AccessToken(accessKey, accessSecret)); setAccessToken(accessKey); setAccessTokenSecret(accessSecret); } }
From source file:org.mule.twitter.TwitterConnector.java
License:Open Source License
private TwitterStream newStream() { ConfigurationBuilder cb = new ConfigurationBuilder().setUseSSL(useSSL).setOAuthConsumerKey(consumerKey) .setOAuthConsumerSecret(consumerSecret).setStreamBaseURL(getStreamBaseUrl()) .setSiteStreamBaseURL(getSiteStreamBaseUrl()).setHttpProxyHost(proxyHost) .setHttpProxyPort(proxyPort).setHttpProxyUser(proxyUsername).setHttpProxyPassword(proxyPassword); if (getAccessToken() != null) { cb.setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessTokenSecret); }/*from w w w . j a v a 2 s. c o m*/ HttpClientHiddenConstructionArgument.setUseMule(false); return new TwitterStreamFactory(cb.build()).getInstance(); }
From source file:org.onebusaway.admin.service.impl.TwitterServiceImpl.java
License:Apache License
@PostConstruct private void setup() { // nothing to do if we are not configured properly if (StringUtils.isBlank(_consumerKey) || StringUtils.isBlank(_consumerSecret) || StringUtils.isBlank(_accessToken) || StringUtils.isBlank(_accessTokenSecret)) { _log.warn("Twitter service missing necessary configuration, exiting"); return;/* w ww . j a v a 2 s. c o m*/ } try { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setOAuthConsumerKey(_consumerKey).setOAuthConsumerSecret(_consumerSecret) .setOAuthAccessToken(_accessToken).setOAuthAccessTokenSecret(_accessTokenSecret); TwitterFactory twitterFactory = new TwitterFactory(configurationBuilder.build()); _twitter = twitterFactory.getInstance(); } catch (Exception any) { // don't let this failure prevent startup _log.error("Twitter integraton failed. Check spring configuration"); _log.error("Configuration exception:", any); } }
From source file:org.onehippo.forge.blog.components.socialmedia.TwitterListing.java
License:Apache License
/** * Builds up the {@link Twitter} object needed to communicate trhrough Twitter4J * * @param request current {@link org.hippoecm.hst.core.component.HstRequest} * @return {@link Twitter} or {@literal null} if configuration is missing in the HST *//* w w w . java2 s . c o m*/ private Twitter getTwitterObject(HstRequest request) { String token = getParameter(TOKEN, request); String tokenSecret = getParameter(TOKEN_SECRET, request); String consumerKey = getParameter(CONSUMER_KEY, request); String consumerSecret = getParameter(CONSUMER_SECRET, request); boolean missingConfiguration = false; if (StringUtils.isBlank(token)) { missingConfiguration = true; log.info("Missing or empty parameter 'token'"); } else if (StringUtils.isBlank(tokenSecret)) { missingConfiguration = true; log.info("Missing or empty parameter 'tokenSecret'"); } else if (StringUtils.isBlank(consumerKey)) { missingConfiguration = true; log.info("Missing or empty parameter 'consumerKey'"); } else if (StringUtils.isBlank(consumerSecret)) { missingConfiguration = true; log.info("Missing or empty parameter 'consumerSecret'"); } if (missingConfiguration) { return null; } ConfigurationBuilder cb = new ConfigurationBuilder().setOAuthAccessToken(token) .setOAuthAccessTokenSecret(tokenSecret).setOAuthConsumerKey(consumerKey) .setOAuthConsumerSecret(consumerSecret); TwitterFactory twitterFactory = new TwitterFactory(cb.build()); return twitterFactory.getInstance(); }
From source file:org.onepercent.utils.twitterstream.agent.src.main.java.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 www. j a va 2s . 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, ""); if (keywordString.trim().length() == 0) { keywords = new String[0]; } else { keywords = keywordString.split(","); for (int i = 0; i < keywords.length; i++) { keywords[i] = keywords[i].trim(); } } String languageString = context.getString(TwitterSourceConstants.LANGUAGE_KEY, ""); if (languageString.trim().length() == 0) { languages = new String[0]; } else { languages = languageString.split(","); for (int i = 0; i < languages.length; i++) { languages[i] = languages[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:org.opennms.netmgt.notifd.MicroblogClient.java
License:Open Source License
public Twitter getTwitter(final String profile) { final MicroblogProfile mp = getProfile(profile); final ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setClientURL(mp.getServiceUrl()); if (!isEmpty(mp.getOauthConsumerKey())) builder.setOAuthConsumerKey(mp.getOauthConsumerKey()); if (!isEmpty(mp.getOauthConsumerSecret())) builder.setOAuthConsumerSecret(mp.getOauthConsumerSecret()); if (!isEmpty(mp.getOauthAccessToken())) builder.setOAuthAccessToken(mp.getOauthAccessToken()); if (!isEmpty(mp.getOauthAccessTokenSecret())) builder.setOAuthAccessTokenSecret(mp.getOauthAccessTokenSecret()); if (!isEmpty(mp.getAuthenUsername())) builder.setUser(mp.getAuthenUsername()); if (!isEmpty(mp.getAuthenPassword())) builder.setPassword(mp.getAuthenPassword()); return new TwitterFactory(builder.build()).getInstance(); }
From source file:org.opensocial.TwitterProxy.java
License:Apache License
public TwitterProxy() { ConfigurationBuilder cb = new ConfigurationBuilder(); Properties props = new Properties(); try {/* w w w. j a v a 2 s . c o m*/ InputStream is = TwitterProxy.class.getClassLoader().getResourceAsStream("TwitterProxy.properties"); props.load(is); cb.setDebugEnabled(true).setOAuthConsumerKey(props.getProperty("oauth_key")) .setOAuthConsumerSecret(props.getProperty("oauth_secret")) .setOAuthAccessToken(props.getProperty("oauth_access_token")) .setOAuthAccessTokenSecret(props.getProperty("oauth_access_token_secret")); } catch (IOException e) { e.printStackTrace(); } tf = new TwitterFactory(cb.build()); twitter = tf.getInstance(); }
From source file:org.ow2.frascati.akka.fabric.peakforecast.lib.TwitterImpl.java
License:Open Source License
@Override public void updateStatus(String message) { try {/*w ww. j a v a 2s . c om*/ ConfigurationBuilder cb = new ConfigurationBuilder(); //info OAuth settings de l'application twitter tweetpeakforecast enregistr par l'utilisateur @peakforecast cb.setDebugEnabled(true).setOAuthConsumerKey("0PqersXnGOn7AirB13jszw") .setOAuthConsumerSecret("r3qyCuhmwRI90JY04kqcYtn5yEl6yaW1UoRhAY08Q") .setOAuthAccessToken("1598158057-epoKcN3Lfz405zjNZQ2rl5cx74lthvBZ93cCsfj") .setOAuthAccessTokenSecret("6YwDPdjS7OpqDHb6PsmW0beOjCgjITzDGYV89gtQU"); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); Status status = twitter.updateStatus(message); System.out.println("Successfully updated the status to [" + status.getText() + "]."); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.primeoservices.cfgateway.twitter.railo.RailoTwitterUserStreamGateway.java
License:Apache License
/** * Initializes this gateway//from www . j a v a 2 s .com */ @Override @SuppressWarnings("rawtypes") public void init(final GatewayEngine engine, final String id, final String cfcPath, final Map config) throws IOException { try { this.argType = ArgumentType.fromConfigValue((String) config.get(ARGUMENT_TYPE)); final ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey((String) config.get(OAUTH_CONSUMER_KEY)); cb.setOAuthConsumerSecret((String) config.get(OAUTH_CONSUMER_SECRET)); cb.setOAuthAccessToken((String) config.get(OAUTH_ACCESS_TOKEN)); cb.setOAuthAccessTokenSecret((String) config.get(OAUTH_ACCESS_SECRET)); cb.setUserStreamRepliesAllEnabled(Boolean.valueOf((String) config.get(ALL_REPLIES))); cb.setJSONStoreEnabled(ArgumentType.JSON.equals(this.argType)); super.init(engine, id, new TwitterUserStream(this, cb.build())); } catch (Throwable t) { final IOException ex = new IOException("Unable to initialize gateway", t); this.onException(ex); throw ex; } }
From source file:org.rapidpm.book.iot.tinkerforge.twitter.TwitterFactory.java
License:Apache License
public TwitterFactory() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("DI0UZvexwirEJ1wl5sw9Vfqx3") .setOAuthConsumerSecret("NQ0Zumw7Li1XbuwzrNHOKquznBgmAJo1sPAoqiNMShqgFufqip") .setOAuthAccessToken("2440296835-4dmuWPOLYUgLjn9ddcXpuloOgDAPO1W0Y5NZSg7") .setOAuthAccessTokenSecret("X9QYzlDKURIxGZbFWoZ7NdvhcFurBfEUVHMTLxtBSrU2x"); tf = new twitter4j.TwitterFactory(cb.build()); }