List of usage examples for twitter4j.conf ConfigurationBuilder build
public Configuration build()
From source file:org.apache.s4.example.twitter.TwitterInputAdapter.java
License:Apache License
public void connectAndRead() throws Exception { ConfigurationBuilder cb = new ConfigurationBuilder(); Properties twitterProperties = new Properties(); File twitter4jPropsFile = new File(System.getProperty("user.home") + "/twitter4j.properties"); if (!twitter4jPropsFile.exists()) { logger.error(//from w w w.j a v a 2s . c o m "Cannot find twitter4j.properties file in this location :[{}]. Make sure it is available at this place and includes user/password credentials", twitter4jPropsFile.getAbsolutePath()); return; } twitterProperties.load(new FileInputStream(twitter4jPropsFile)); cb.setDebugEnabled(Boolean.valueOf(twitterProperties.getProperty("debug"))) .setUser(twitterProperties.getProperty("user")) .setPassword(twitterProperties.getProperty("password")); TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); StatusListener statusListener = new StatusListener() { @Override public void onException(Exception ex) { logger.error("error", ex); } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { logger.error("error"); } @Override public void onStatus(Status status) { messageQueue.add(status); } @Override public void onScrubGeo(long userId, long upToStatusId) { logger.error("error"); } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { logger.error("error"); } }; twitterStream.addListener(statusListener); twitterStream.sample(); }
From source file:org.apache.solr.handler.dataimport.TwitterEntityProcessor.java
License:Apache License
public void init(Context context) { super.init(context); // get parameters String consumerKey = getStringFromContext("consumerKey", null); String consumerSecret = getStringFromContext("consumerSecret", null); String accessToken = getStringFromContext("accessToken", null); String accessTokenSecret = getStringFromContext("accessTokenSecret", null); // connect to twitter ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey(consumerKey); cb.setOAuthConsumerSecret(consumerSecret); cb.setOAuthAccessToken(accessToken); cb.setOAuthAccessTokenSecret(accessTokenSecret); twitter = new TwitterFactory(cb.build()).getInstance(); // initiate the search String criteria = getStringFromContext("criteria", null); since = context.replaceTokens("${dih.last_index_time}"); query = new Query(criteria); //query.setSince(since.substring(0, since.indexOf(" ")).trim()); query.setSince("2015-02-12"); index = 0;/*from ww w . jav a 2 s . com*/ logConfig(); }
From source file:org.apache.streams.twitter.processor.FetchAndReplaceTwitterProcessor.java
License:Apache License
protected Twitter getTwitterClient() { if (this.client == null) { String baseUrl = "https://api.twitter.com:443/1.1/"; ConfigurationBuilder builder = new ConfigurationBuilder() .setOAuthConsumerKey(config.getOauth().getConsumerKey()) .setOAuthConsumerSecret(config.getOauth().getConsumerSecret()) .setOAuthAccessToken(config.getOauth().getAccessToken()) .setOAuthAccessTokenSecret(config.getOauth().getAccessTokenSecret()) .setIncludeEntitiesEnabled(true).setJSONStoreEnabled(true).setAsyncNumThreads(1) .setRestBaseURL(baseUrl).setIncludeMyRetweetEnabled(Boolean.TRUE) .setPrettyDebugEnabled(Boolean.TRUE); this.client = new TwitterFactory(builder.build()).getInstance(); }/* w w w . jav a 2 s. c om*/ return this.client; }
From source file:org.apache.streams.twitter.provider.TwitterTimelineProvider.java
License:Apache License
public Twitter getTwitterClient() { String baseUrl = "https://api.twitter.com:443/1.1/"; ConfigurationBuilder builder = new ConfigurationBuilder() .setOAuthConsumerKey(config.getOauth().getConsumerKey()) .setOAuthConsumerSecret(config.getOauth().getConsumerSecret()) .setOAuthAccessToken(config.getOauth().getAccessToken()) .setOAuthAccessTokenSecret(config.getOauth().getAccessTokenSecret()).setIncludeEntitiesEnabled(true) .setJSONStoreEnabled(true).setAsyncNumThreads(3).setRestBaseURL(baseUrl) .setIncludeMyRetweetEnabled(Boolean.TRUE).setPrettyDebugEnabled(Boolean.TRUE); return new TwitterFactory(builder.build()).getInstance(); }
From source file:org.apache.streams.twitter.provider.TwitterUserInformationProvider.java
License:Apache License
protected Twitter getTwitterClient() { String baseUrl = "https://api.twitter.com:443/1.1/"; ConfigurationBuilder builder = new ConfigurationBuilder() .setOAuthConsumerKey(twitterUserInformationConfiguration.getOauth().getConsumerKey()) .setOAuthConsumerSecret(twitterUserInformationConfiguration.getOauth().getConsumerSecret()) .setOAuthAccessToken(twitterUserInformationConfiguration.getOauth().getAccessToken()) .setOAuthAccessTokenSecret(twitterUserInformationConfiguration.getOauth().getAccessTokenSecret()) .setIncludeEntitiesEnabled(true).setJSONStoreEnabled(true).setAsyncNumThreads(3) .setRestBaseURL(baseUrl).setIncludeMyRetweetEnabled(Boolean.TRUE) .setPrettyDebugEnabled(Boolean.TRUE); return new TwitterFactory(builder.build()).getInstance(); }
From source file:org.apparatus_templi.service.TwitterService.java
License:Open Source License
private void start() { accessToken = Coordinator.getPrefs().getPreference(Prefs.Keys.twtrAccess); accessTokenKey = Coordinator.getPrefs().getPreference(Prefs.Keys.twtrAccessKey); if (accessToken != null && accessTokenKey != null) { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(CONSUMER_KEY).setOAuthConsumerSecret(CONSUMER_SECRET) .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessTokenKey); TwitterFactory tf = new TwitterFactory(cb.build()); twitter = tf.getInstance();/* w w w.jav a 2 s . c o m*/ } else { Log.e(TAG, "Twitter service requires authentication for a particular user account."); } }
From source file:org.bireme.interop.toJson.Twitter2Json.java
License:Open Source License
public Twitter2Json(final String userId, final Query query, final int total, final Date lowerDate, final boolean useRetweets) throws TwitterException { assert ((userId != null) || (query != null)); assert ((total >= 1) || (lowerDate != null)); final ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("LmvfpL4pJE7PJr0CgJUuQKZOy") .setOAuthConsumerSecret("UP1VIf4K3jGDvOYYXh0zshHnuj8HSUMDTWlJEEhGMWIJHKGXSJ") .setOAuthAccessToken("2788081964-9C7j4ZBOsdIy9tmtMkong54QimvjkwopXdLqecm") .setOAuthAccessTokenSecret("swwqLPLWppweF3KRKe2zpU9qPNFDbsZm9OqQ5scX9vVCp"); final Twitter twitter = new TwitterFactory(cb.build()).getInstance(); this.loader = new TweetLoader(twitter, userId, query, total, lowerDate, useRetweets); next = getNext();// w w w . j a v a2s . co m }
From source file:org.botlibre.sense.twitter.Twitter.java
License:Open Source License
public void connect() throws TwitterException { initProperties();/*from w ww .j a va 2 s . co m*/ ConfigurationBuilder config = new ConfigurationBuilder(); config.setOAuthConsumerKey(getOauthKey()); config.setOAuthConsumerSecret(getOauthSecret()); config.setOAuthAccessToken(getToken()); config.setOAuthAccessTokenSecret(getTokenSecret()); twitter4j.Twitter twitter = new TwitterFactory(config.build()).getInstance(); User user = twitter.verifyCredentials(); if (!this.userName.equals(user.getScreenName())) { this.userName = user.getScreenName(); saveProperties(null); } //AccessToken accessToken = new AccessToken(getToken(), getTokenSecret()); //twitter4j.Twitter twitter = new TwitterFactory().getInstance(accessToken); //twitter4j.Twitter twitter = new TwitterFactory().getInstance(getOauthKey(), getOauthSecret(), accessToken); //twitter4j.Twitter twitter = new TwitterFactory().getInstance(getUsername(), getPassword()); setConnection(twitter); }
From source file:org.brunocvcunha.taskerbox.impl.twitter.TwitterChannel.java
License:Apache License
@Override public void setup() throws IllegalStateException, TwitterException { logInfo(log, "Twitter setup..."); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(this.consumerKey).setOAuthConsumerSecret(this.consumerSecret) .setOAuthAccessToken(this.accessToken).setOAuthAccessTokenSecret(this.accessTokenSecret); TwitterFactory tf = new TwitterFactory(cb.build()); this.twitter = tf.getInstance(); this.loggedUser = this.twitter.getScreenName(); logInfo(log, "Twitter setup finished! Logged user is " + this.loggedUser); }
From source file:org.btcwolf.twitter.TwitterAgent.java
License:Open Source License
public TwitterAgent() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(SettingsProvider.getProperty(CONSUMER_KEY)) .setOAuthConsumerSecret(SettingsProvider.getProperty(CONSUMER_SECRET)) .setOAuthAccessToken(SettingsProvider.getProperty(ACCESS_TOKEN)) .setOAuthAccessTokenSecret(SettingsProvider.getProperty(TOKEN_SECRET)); this.twitter = new TwitterFactory(cb.build()); }