String consumerKey = conf.getOAuthConsumerKey(); String consumerSecret = conf.getOAuthConsumerSecret(); if (conf.isApplicationOnlyAuthEnabled()) { OAuth2Authorization oauth2 = new OAuth2Authorization(conf); String tokenType = conf.getOAuth2TokenType(); String accessToken = conf.getOAuth2AccessToken(); if (tokenType != null && accessToken != null) { oauth2.setOAuth2Token(new OAuth2Token(tokenType, accessToken)); OAuthAuthorization oauth; oauth = new OAuthAuthorization(conf); String accessToken = conf.getOAuthAccessToken(); String accessTokenSecret = conf.getOAuthAccessTokenSecret(); if (accessToken != null && accessTokenSecret != null) { oauth.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret)); String screenName = conf.getUser(); String password = conf.getPassword(); if (screenName != null && password != null) { auth = new BasicAuthorization(screenName, password);
static ResponseList<Location> createLocationList(HttpResponse res, Configuration conf) throws TwitterException { if (conf.isJSONStoreEnabled()) { TwitterObjectFactory.clearThreadLocalMap(); } return createLocationList(res.asJSONArray(), conf.isJSONStoreEnabled()); }
private void init() { if (null == auth) { String consumerKey = conf.getOAuthConsumerKey(); String consumerSecret = conf.getOAuthConsumerSecret(); if (conf.isApplicationOnlyAuthEnabled()) { OAuth2Authorization oauth2 = new OAuth2Authorization(conf); String tokenType = conf.getOAuth2TokenType(); String accessToken = conf.getOAuth2AccessToken(); if (tokenType != null && accessToken != null) { oauth2.setOAuth2Token(new OAuth2Token(tokenType, accessToken)); String accessToken = conf.getOAuthAccessToken(); String accessTokenSecret = conf.getOAuthAccessTokenSecret(); if (accessToken != null && accessTokenSecret != null) { oauth.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret)); http = HttpClientFactory.getInstance(conf.getHttpClientConfiguration()); setFactory();
/** * @param conf configuration */ public OAuthAuthorization(Configuration conf) { this.conf = conf; http = HttpClientFactory.getInstance(conf.getHttpClientConfiguration()); setOAuthConsumer(conf.getOAuthConsumerKey(), conf.getOAuthConsumerSecret()); if (conf.getOAuthAccessToken() != null && conf.getOAuthAccessTokenSecret() != null) { setOAuthAccessToken(new AccessToken(conf.getOAuthAccessToken(), conf.getOAuthAccessTokenSecret())); } }
public OAuth2Authorization(Configuration conf) { this.conf = conf; setOAuthConsumer(conf.getOAuthConsumerKey(), conf.getOAuthConsumerSecret()); http = HttpClientFactory.getInstance(conf.getHttpClientConfiguration()); }
TwitterImpl(Configuration conf, Authorization auth) { super(conf, auth); INCLUDE_MY_RETWEET = new HttpParameter("include_my_retweet", conf.isIncludeMyRetweetEnabled()); if (implicitParamsMap.containsKey(conf)) { this.IMPLICIT_PARAMS = implicitParamsMap.get(conf); this.IMPLICIT_PARAMS_STR = implicitParamsStrMap.get(conf); } else { String implicitParamsStr = conf.isIncludeEntitiesEnabled() ? "include_entities=" + true : ""; boolean contributorsEnabled = conf.getContributingTo() != -1L; if (contributorsEnabled) { if (!"".equals(implicitParamsStr)) { implicitParamsStr += "&"; implicitParamsStr += "contributingto=" + conf.getContributingTo(); if (conf.isTweetModeExtended()) { if (!"".equals(implicitParamsStr)) { implicitParamsStr += "&"; if (conf.isIncludeEntitiesEnabled()) { params.add(new HttpParameter("include_entities", "true")); params.add(new HttpParameter("contributingto", conf.getContributingTo())); if (conf.isTrimUserEnabled()) { params.add(new HttpParameter("trim_user", "1")); if (conf.isIncludeExtAltTextEnabled()) { params.add(new HttpParameter("include_ext_alt_text", "true"));
/** * Returns a OAuth Authenticated instance.<br> * consumer key and consumer Secret must be provided by twitter4j.properties, or system properties. * Unlike {@link TwitterStream#setOAuthAccessToken(twitter4j.auth.AccessToken)}, this factory method potentially returns a cached instance. * * @param accessToken access token * @return an instance */ public TwitterStream getInstance(AccessToken accessToken) { String consumerKey = conf.getOAuthConsumerKey(); String consumerSecret = conf.getOAuthConsumerSecret(); if (null == consumerKey && null == consumerSecret) { throw new IllegalStateException("Consumer key and Consumer secret not supplied."); } OAuthAuthorization oauth = new OAuthAuthorization(conf); oauth.setOAuthAccessToken(accessToken); return getInstance(conf, oauth); }
@Override public boolean isGZIPEnabled() { return nestedConf.getHttpClientConfiguration().isGZIPEnabled(); } }
if (CONF.isJSONStoreEnabled()) { TwitterObjectFactory.clearThreadLocalMap(); JSONObjectType.Type event = JSONObjectType.determine(json); if (logger.isDebugEnabled()) { logger.debug("Received:", CONF.getHttpClientConfiguration().isPrettyDebugEnabled() ? json.toString(1) : json.toString()); case UNKNOWN: default: logger.warn("Received unknown event:", CONF.getHttpClientConfiguration().isPrettyDebugEnabled() ? json.toString(1) : json.toString());
/** {@inheritDoc} */ @Override public int send(final List<Argument> arguments) { final Twitter svc = buildUblogService(arguments); String destUser = findDestName(arguments); Status response; if (destUser == null || "".equals(destUser)) { LOG.error("Cannot send a microblog reply notice to a user with no microblog username set. Either set a microblog username for this OpenNMS user or use the MicroblogUpdateNotificationStrategy instead."); return 1; } // In case the user tried to be helpful, avoid a double @@ if (destUser.startsWith("@")) destUser = destUser.substring(1); final String fullMessage = String.format("@%s %s", destUser, buildMessageBody(arguments)); LOG.debug("Dispatching microblog reply notification at base URL '{}' with message '{}'", svc.getConfiguration().getClientURL(), fullMessage); try { response = svc.updateStatus(fullMessage); } catch (final TwitterException e) { LOG.error("Microblog notification failed at service URL '{}'", svc.getConfiguration().getClientURL(), e); return 1; } LOG.info("Microblog reply notification succeeded: reply update posted with ID {}", response.getId()); return 0; }
@Override public int getHttpReadTimeout() { // this is the trick that overrides connection timeout return nestedConf.getHttpStreamingReadTimeout(); }
public DispatcherFactory(Configuration conf) { dispatcherImpl = conf.getDispatcherImpl(); this.conf = conf; }
public DispatcherImpl(final Configuration conf) { executorService = Executors.newFixedThreadPool(conf.getAsyncNumThreads(), new ThreadFactory() { int count = 0; @Override public Thread newThread(Runnable r) { Thread thread = new Thread(r); thread.setName(String.format("Twitter4J Async Dispatcher[%d]", count++)); thread.setDaemon(conf.isDaemonEnabled()); return thread; } } ); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { executorService.shutdown(); } }); }
/** * Returns a OAuth Authenticated instance.<br> * consumer key and consumer Secret must be provided by twitter4j.properties, or system properties.<br> * Unlike {@link Twitter#setOAuthAccessToken(twitter4j.auth.AccessToken)}, this factory method potentially returns a cached instance. * * @param accessToken access token * @return an instance * @since Twitter4J 2.1.9 */ public Twitter getInstance(AccessToken accessToken) { String consumerKey = conf.getOAuthConsumerKey(); String consumerSecret = conf.getOAuthConsumerSecret(); if (null == consumerKey && null == consumerSecret) { throw new IllegalStateException("Consumer key and Consumer secret not supplied."); } OAuthAuthorization oauth = new OAuthAuthorization(conf); oauth.setOAuthAccessToken(accessToken); return getInstance(oauth); }
@Override public boolean isHttpProxySocks() { return nestedConf.getHttpClientConfiguration().isHttpProxySocks(); }
/** {@inheritDoc} */ @Override public int send(List<Argument> arguments) { Twitter svc = buildUblogService(arguments); String destUser = findDestName(arguments); DirectMessage response; if (destUser == null || "".equals(destUser)) { LOG.error("Cannot send a microblog DM notice to a user with no microblog username set. Either set a microblog username for this OpenNMS user or use the MicroblogUpdateNotificationStrategy instead."); return 1; } // In case the user tried to be helpful, avoid a double @@ if (destUser.startsWith("@")) destUser = destUser.substring(1); String fullMessage = buildMessageBody(arguments); LOG.debug("Dispatching microblog DM notification at base URL '{}' with destination user '{}' and message '{}'", svc.getConfiguration().getClientURL(), destUser, fullMessage); try { response = svc.sendDirectMessage(destUser, fullMessage); } catch (TwitterException e) { LOG.error("Microblog notification failed at service URL '{}' to destination user '{}'", svc.getConfiguration().getClientURL(), destUser, e); return 1; } LOG.info("Microblog DM notification succeeded: DM sent with ID {}", response.getId()); return 0; } }
/*package*/ UserListJSONImpl(HttpResponse res, Configuration conf) throws TwitterException { super(res); if (conf.isJSONStoreEnabled()) { TwitterObjectFactory.clearThreadLocalMap(); } JSONObject json = res.asJSONObject(); init(json); if (conf.isJSONStoreEnabled()) { TwitterObjectFactory.registerJSONObject(this, json); } }
/** * Returns a OAuth Authenticated instance.<br> * consumer key and consumer Secret must be provided by twitter4j.properties, or system properties.<br> * Unlike {@link AsyncTwitter#setOAuthAccessToken(twitter4j.auth.AccessToken)}, this factory method potentially returns a cached instance. * * @param accessToken access token * @return an instance */ public AsyncTwitter getInstance(AccessToken accessToken) { String consumerKey = conf.getOAuthConsumerKey(); String consumerSecret = conf.getOAuthConsumerSecret(); if (null == consumerKey && null == consumerSecret) { throw new IllegalStateException("Consumer key and Consumer secret not supplied."); } OAuthAuthorization oauth = new OAuthAuthorization(conf); oauth.setOAuthConsumer(consumerKey, consumerSecret); oauth.setOAuthAccessToken(accessToken); return new AsyncTwitterImpl(conf, oauth); }
@Override public int getHttpRetryCount() { return nestedConf.getHttpClientConfiguration().getHttpRetryCount(); }
/** {@inheritDoc} */ @Override public int send(List<Argument> arguments) { Twitter svc = buildUblogService(arguments); String messageBody = buildMessageBody(arguments); Status response; final String baseURL = svc.getConfiguration().getClientURL(); LOG.debug("Dispatching microblog notification at base URL '{}' with message '{}'", baseURL, messageBody); try { response = svc.updateStatus(messageBody); } catch (TwitterException e) { LOG.error("Microblog notification failed at service URL '{}'", baseURL, e); return 1; } LOG.info("Microblog notification succeeded: update posted with ID {}", response.getId()); return 0; }