Java Code Examples for twitter4j.conf.ConfigurationBuilder#build()

The following examples show how to use twitter4j.conf.ConfigurationBuilder#build() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PlayConfigurationView.java    From beatoraja with GNU General Public License v3.0 6 votes vote down vote up
@FXML
public void startTwitterAuth() {
	ConfigurationBuilder cb = new ConfigurationBuilder();
	cb.setOAuthConsumerKey(txtTwitterConsumerKey.getText());
	cb.setOAuthConsumerSecret(txtTwitterConsumerSecret.getText());
	cb.setOAuthAccessToken(null);
	cb.setOAuthAccessTokenSecret(null);
	TwitterFactory twitterfactory = new TwitterFactory(cb.build());
	Twitter twitter = twitterfactory.getInstance();
	try {
		requestToken = twitter.getOAuthRequestToken();
		Desktop desktop = Desktop.getDesktop();
		URI uri = new URI(requestToken.getAuthorizationURL());
		desktop.browse(uri);
		player.setTwitterConsumerKey(txtTwitterConsumerKey.getText());
		player.setTwitterConsumerSecret(txtTwitterConsumerSecret.getText());
		player.setTwitterAccessToken("");
		player.setTwitterAccessTokenSecret("");
		txtTwitterPIN.setDisable(false);
		twitterPINButton.setDisable(false);
		txtTwitterAuthenticated.setVisible(false);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 2
Source File: TweetEmitter.java    From storm-example with Apache License 2.0 6 votes vote down vote up
public TweetEmitter() {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("DJSv02qbCiCVY6Sy8uz8Cg")
            .setOAuthConsumerSecret("iVa3GGSl9NrHvu3AAXm6zBV7Z2XTvtuDkAMiArHlGM")
            .setOAuthAccessToken("1353264175-5EWRtEHoaJ6zfmAG5BEn7Uc7E8qg7P531oddm08")
            .setOAuthAccessTokenSecret("ss7YCprReDBEpm4AGnguqB1xNCUwyRGli5Q33yImf0");
    TwitterFactory tf = new TwitterFactory(cb.build());
    twitter = tf.getInstance();
    query = new Query(SEARCH_PHRASE);
    query.setLang("en");
    long now = System.currentTimeMillis();
    if (now - lastFetch > FETCH_PERIODICITY) {
        try {
            result = twitter.search(query);
        } catch (TwitterException e) {
            throw new RuntimeException(e);
        }
    }
}
 
Example 3
Source File: PlayConfigurationView.java    From beatoraja with GNU General Public License v3.0 6 votes vote down vote up
@FXML
public void startPINAuth() {
	ConfigurationBuilder cb = new ConfigurationBuilder();
	cb.setOAuthConsumerKey(player.getTwitterConsumerKey());
	cb.setOAuthConsumerSecret(player.getTwitterConsumerSecret());
	cb.setOAuthAccessToken(null);
	cb.setOAuthAccessTokenSecret(null);
	TwitterFactory twitterfactory = new TwitterFactory(cb.build());
	Twitter twitter = twitterfactory.getInstance();
	try {
		AccessToken accessToken = twitter.getOAuthAccessToken(requestToken, txtTwitterPIN.getText());
		player.setTwitterAccessToken(accessToken.getToken());
		player.setTwitterAccessTokenSecret(accessToken.getTokenSecret());
		commit();
		update(config);
	} catch (TwitterException e) {
		e.printStackTrace();
	}
}
 
Example 4
Source File: Twitter.java    From jacamo with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Instantiate a twitter artifact configured with a consumer
 * key/secret and an access token/secret got for accessing
 * a Twitter account-
 */
void  init(String consumerKey, String consumerSecret, String accessToken, String accessSecret) {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true)
         .setOAuthConsumerKey(consumerKey)
           .setOAuthConsumerSecret(consumerSecret)
           .setOAuthAccessToken(accessToken)
           .setOAuthAccessTokenSecret(accessSecret);

    factory = new TwitterFactory(cb.build());
    twitter = factory.getInstance();

    try {
        List<Status> statuses = twitter.getHomeTimeline();
        defineObsProperty("tw_user_status",statuses.get(0).getText());
    } catch (Exception ex){
        ex.printStackTrace();
        defineObsProperty("tw_user_status","");
    }
}
 
Example 5
Source File: TweetLaunchpad.java    From The-NOC-List with Apache License 2.0 6 votes vote down vote up
public Twitter getTwitter() throws TwitterException, IOException 
{
   	ConfigurationBuilder cb = new ConfigurationBuilder();
   	
   	cb.setDebugEnabled(true)
   	  .setOAuthConsumerKey(CONSUMER_KEY)
   	  .setOAuthConsumerSecret(CONSUMER_KEY_SECRET);
   	
   	TwitterFactory tf = new TwitterFactory(cb.build());
   	Twitter twitter = tf.getInstance();
   	
   	twitter.setOAuthAccessToken(new AccessToken(ACCESS_TOKEN, 
   												ACCESS_TOKEN_SECRET));

   	return twitter;
}
 
Example 6
Source File: TweetSearcher.java    From The-NOC-List with Apache License 2.0 6 votes vote down vote up
public Twitter getTwitter() throws TwitterException, IOException 
{
   	ConfigurationBuilder cb = new ConfigurationBuilder();
   	
   	cb.setDebugEnabled(true)
   	  .setOAuthConsumerKey(CONSUMER_KEY)
   	  .setOAuthConsumerSecret(CONSUMER_SECRET)
   	  .setOAuthAccessToken(ACCESS_TOKEN)
   	  .setOAuthAccessTokenSecret(ACCESS_SECRET);
   	
   	TwitterFactory tf = new TwitterFactory(cb.build());
   	Twitter twitter = tf.getInstance();
   	
   	twitter.setOAuthAccessToken(new AccessToken(ACCESS_TOKEN, ACCESS_SECRET));

   	return twitter;
}
 
Example 7
Source File: TwitterSentimentJobManager.java    From Babler with Apache License 2.0 6 votes vote down vote up
public TwitterSentimentJobManager()
{
    languageDetector = new LanguageDetector();

    for(int i =0; i< twitKey.length; i++)
    {
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true)
                .setOAuthConsumerKey(twitKey[i].getConsumer())
                .setOAuthConsumerSecret(twitKey[i].getSecret())
                .setOAuthAccessToken(twitKey[i].getAccess())
                .setOAuthAccessTokenSecret(twitKey[i].getToken_secret());

        TwitterFactory tf = new TwitterFactory(cb.build());
        keys[i] = tf.getInstance();
    }
}
 
Example 8
Source File: TwitterJobManager.java    From Babler with Apache License 2.0 6 votes vote down vote up
public TwitterJobManager()
{

    languageDetector = new LanguageDetector();

    for(int i =0; i< twitKey.length; i++)
    {
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true)
                .setOAuthConsumerKey(twitKey[i].getConsumer())
                .setOAuthConsumerSecret(twitKey[i].getSecret())
                .setOAuthAccessToken(twitKey[i].getAccess())
                .setOAuthAccessTokenSecret(twitKey[i].getToken_secret());

        TwitterFactory tf = new TwitterFactory(cb.build());
        keys[i] = tf.getInstance();

    }
}
 
Example 9
Source File: TwitterCodeSwitchSJobManager.java    From Babler with Apache License 2.0 6 votes vote down vote up
public TwitterCodeSwitchSJobManager()
{
    languageDetector = new LanguageDetector();

    for(int i =0; i< twitKey.length; i++)
    {
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true)
                .setOAuthConsumerKey(twitKey[i].getConsumer())
                .setOAuthConsumerSecret(twitKey[i].getSecret())
                .setOAuthAccessToken(twitKey[i].getAccess())
                .setOAuthAccessTokenSecret(twitKey[i].getToken_secret());

        TwitterFactory tf = new TwitterFactory(cb.build());
        keys[i] = tf.getInstance();
    }
}
 
Example 10
Source File: TwitterJobManagerUser.java    From Babler with Apache License 2.0 6 votes vote down vote up
public TwitterJobManagerUser()
{
    languageDetector = new LanguageDetector();

    for(int i =0; i< twitKey.length; i++)
    {
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true)
                .setOAuthConsumerKey(twitKey[i].getConsumer())
                .setOAuthConsumerSecret(twitKey[i].getSecret())
                .setOAuthAccessToken(twitKey[i].getAccess())
                .setOAuthAccessTokenSecret(twitKey[i].getToken_secret());

        TwitterFactory tf = new TwitterFactory(cb.build());
        keys[i] = tf.getInstance();

    }
}
 
Example 11
Source File: NotificationResource.java    From sample-acmegifts with Eclipse Public License 1.0 5 votes vote down vote up
@PostConstruct
public void init() {
  try {
    File log = new File(logFile);
    File parentDir = log.getParentFile();
    if (!parentDir.exists()) {
      parentDir.mkdirs();
    }

    FileHandler fh = new FileHandler(logFile);
    logger.addHandler(fh);
    SimpleFormatter formatter = new SimpleFormatter();
    fh.setFormatter(formatter);

    File fbLog = new File(fallbackLogFile);
    File fbParentDir = fbLog.getParentFile();
    if (!fbParentDir.exists()) {
      fbParentDir.mkdirs();
    }

    FileHandler fbFh = new FileHandler(fallbackLogFile);
    fbLogger.addHandler(fbFh);
    SimpleFormatter fbFormatter = new SimpleFormatter();
    fbFh.setFormatter(fbFormatter);

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true);
    cb.setTweetModeExtended(true);
    cb.setOAuthConsumerKey(consumerKey);
    cb.setOAuthConsumerSecret(consumeSecret);
    cb.setOAuthAccessToken(accessToken);
    cb.setOAuthAccessTokenSecret(acessSecret);
    TwitterFactory tf = new TwitterFactory(cb.build());
    twitter = tf.getInstance();
  } catch (Exception e) {
    throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
  }
}
 
Example 12
Source File: SigninServlet.java    From TwitterBoost-Tools with MIT License 5 votes vote down vote up
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// configure twitter api with consumer key and secret key
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
  .setOAuthConsumerKey(Setup.CONSUMER_KEY)
  .setOAuthConsumerSecret(Setup.CONSUMER_SECRET);
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
request.getSession().setAttribute("twitter", twitter);
try {
	
	// setup callback URL
    StringBuffer callbackURL = request.getRequestURL();
    int index = callbackURL.lastIndexOf("/");
    callbackURL.replace(index, callbackURL.length(), "").append("/callback");

    // get request object and save to session
    RequestToken requestToken = twitter.getOAuthRequestToken(callbackURL.toString());
    request.getSession().setAttribute("requestToken", requestToken);
    
    // redirect to twitter authentication URL
    response.sendRedirect(requestToken.getAuthenticationURL());

} catch (TwitterException e) {
    throw new ServletException(e);
}

  }
 
Example 13
Source File: TwitterApiWrapper.java    From data-transfer-project with Apache License 2.0 5 votes vote down vote up
static  Twitter getInstance(
    AppCredentials appCredentials,
    TokenSecretAuthData authData) {

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(false)
        .setOAuthConsumerKey(appCredentials.getKey())
        .setOAuthConsumerSecret(appCredentials.getSecret())
        // TODO: I think the token/secret expire, we need to check into refreshing them
        .setOAuthAccessToken(authData.getToken())
        .setOAuthAccessTokenSecret(authData.getSecret());
    TwitterFactory tf = new TwitterFactory(cb.build());
    return tf.getInstance();
}
 
Example 14
Source File: SparkBatchProcessingTest.java    From OSTMap with Apache License 2.0 5 votes vote down vote up
private static OAuthAuthorization getOAuthoirzation(PropertiesLoaderJ propertiesLoader){
    ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
    configurationBuilder.setOAuthConsumerKey(propertiesLoader.oAuthConsumerKey)
            .setOAuthConsumerSecret(propertiesLoader.oAuthConsumerSecret)
            .setOAuthAccessToken(propertiesLoader.oAuthAccessToken)
            .setOAuthAccessTokenSecret(propertiesLoader.oAuthAccessTokenSecret);
    return new OAuthAuthorization(configurationBuilder.build());
}
 
Example 15
Source File: TwitterShowUserServlet.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
protected void doGet(final HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    TwitterOAuthResponse twitterOAuthResponse = getTwitterOAuthResponse(request);
    ConfigurationBuilder cb = new ConfigurationBuilder();

    cb.setDebugEnabled(true)
            .setOAuthConsumerKey(this.identityProvider.getConfig().get("clientId"))
            .setOAuthConsumerSecret(this.identityProvider.getConfig().get("clientSecret"))
            .setOAuthAccessToken(twitterOAuthResponse.getToken())
            .setOAuthAccessTokenSecret(twitterOAuthResponse.getTokenSecret());

    TwitterFactory tf = new TwitterFactory(cb.build());
    Twitter twitter = tf.getInstance();

    try {
        User user = twitter.users().showUser(twitterOAuthResponse.getScreenName());

        response.setContentType(MediaType.APPLICATION_JSON);

        PrintWriter writer = response.getWriter();

        writer.println(new ObjectMapper().writeValueAsString(user));

        writer.flush();
    } catch (TwitterException e) {
        throw new RuntimeException("Could not load social profile.", e);
    }
}
 
Example 16
Source File: Twitter4JHelper.java    From personality-insights-twitter-java with Apache License 2.0 5 votes vote down vote up
/**
 * Instantiates a new twitter 4 J helper.
 *
 * @param properties the properties
 * @throws Exception the exception
 */
public Twitter4JHelper(Properties properties) throws Exception {
  String consumerKey = properties.getProperty(CONSUMER_KEY);
  String consumerSecret = properties.getProperty(CONSUMER_SECRET);
  String accessToken = properties.getProperty(ACCESS_TOKEN);
  String accessSecret = properties.getProperty(ACCESS_SECRET);

  // Validate that these are set and throw an error if they are not
  if (consumerKey == null || consumerKey.isEmpty()) {
    throw new Exception(CONSUMER_KEY + " cannot be null");
  }
  if (consumerSecret == null || consumerSecret.isEmpty()) {
    throw new Exception(CONSUMER_SECRET + " cannot be null");
  }
  if (accessToken == null || accessToken.isEmpty()) {
    throw new Exception(ACCESS_TOKEN + " cannot be null");
  }
  if (accessSecret == null || accessSecret.isEmpty()) {
    throw new Exception(ACCESS_SECRET + " cannot be null");
  }

  ConfigurationBuilder cb = new ConfigurationBuilder();
  cb.setDebugEnabled(true)
    .setOAuthConsumerKey(consumerKey)
    .setOAuthConsumerSecret(consumerSecret)
    .setOAuthAccessToken(accessToken)
    .setOAuthAccessTokenSecret(accessSecret);

  TwitterFactory twitterFactory = new TwitterFactory(cb.build());
  client = twitterFactory.getInstance();
  client.addRateLimitStatusListener(this);
}
 
Example 17
Source File: TwitterOauthWizard.java    From Onosendai with Apache License 2.0 5 votes vote down vote up
private Configuration getTwitterConfiguration () {
	if (this.twitterConfiguration == null) {
		final ConfigurationBuilder builder = new ConfigurationBuilder();
		builder.setOAuthConsumerKey(TwitterOauth.getConsumerKey());
		builder.setOAuthConsumerSecret(TwitterOauth.getConsumerSecret());
		this.twitterConfiguration = builder.build();
	}
	return this.twitterConfiguration;
}
 
Example 18
Source File: TwitterInstance.java    From android-opensource-library-56 with Apache License 2.0 5 votes vote down vote up
public static Twitter getTwitterInstance(Context context) {
    if (INSTANCE == null) {
        Settings settings = Settings.getInstance(context);
        ConfigurationBuilder cbuilder = new ConfigurationBuilder();
        cbuilder.setOAuthConsumerKey(Settings.CONSUMER_KEY);
        cbuilder.setOAuthConsumerSecret(Settings.CONSUMER_SECRET);
        cbuilder.setOAuthAccessToken(settings.getAccessToken());
        cbuilder.setOAuthAccessTokenSecret(settings.getAccessTokenSecret());
        Configuration c = cbuilder.build();
        TwitterFactory twitterFactory = new TwitterFactory(c);
        INSTANCE = twitterFactory.getInstance();
    }
    return INSTANCE;
}
 
Example 19
Source File: SoomlaTwitter.java    From android-profile with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void configure(Map<String, String> providerParams) {
    autoLogin = false;

    if (providerParams != null) {
        twitterConsumerKey = providerParams.get("consumerKey");
        twitterConsumerSecret = providerParams.get("consumerSecret");

        // extract autoLogin
        String autoLoginStr = providerParams.get("autoLogin");
        autoLogin = autoLoginStr != null && Boolean.parseBoolean(autoLoginStr);
    }

    SoomlaUtils.LogDebug(TAG, String.format(
                "ConsumerKey:%s ConsumerSecret:%s",
                twitterConsumerKey, twitterConsumerSecret));

    if (TextUtils.isEmpty(twitterConsumerKey) || TextUtils.isEmpty(twitterConsumerSecret)) {
        SoomlaUtils.LogError(TAG, "You must provide the Consumer Key and Secret in the SoomlaProfile initialization parameters");
        isInitialized = false;
    }
    else {
        isInitialized = true;
    }

    oauthCallbackURL = "oauth://soomla_twitter" + twitterConsumerKey;

    ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
    configurationBuilder.setOAuthConsumerKey(twitterConsumerKey);
    configurationBuilder.setOAuthConsumerSecret(twitterConsumerSecret);
    Configuration configuration = configurationBuilder.build();
    twitter = new AsyncTwitterFactory(configuration).getInstance();

    if (!actionsListenerAdded) {
        SoomlaUtils.LogWarning(TAG, "added action listener");
        twitter.addListener(actionsListener);
        actionsListenerAdded = true;
    }
}
 
Example 20
Source File: TwitterProvider.java    From Onosendai with Apache License 2.0 5 votes vote down vote up
private static TwitterFactory makeTwitterFactory (final Account account) {
	final ConfigurationBuilder cb = new ConfigurationBuilder()
			.setOAuthConsumerKey(account.getConsumerKey())
			.setOAuthConsumerSecret(account.getConsumerSecret())
			.setOAuthAccessToken(account.getAccessToken())
			.setOAuthAccessTokenSecret(account.getAccessSecret())
			.setTweetModeExtended(true)
			.setIncludeExtAltTextEnabled(true);
	return new TwitterFactory(cb.build());
}