Example usage for twitter4j.conf ConfigurationBuilder build

List of usage examples for twitter4j.conf ConfigurationBuilder build

Introduction

In this page you can find the example usage for twitter4j.conf ConfigurationBuilder build.

Prototype

public Configuration build() 

Source Link

Usage

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;//from   ww w  .j  a  v a 2 s. co 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
 *///  ww  w .  j  a v a2 s  . co 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  w  w  w.j a v a2s . 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 {/*from ww  w  .j a  v  a 2s . 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 {//from w  w  w. j ava 2  s.  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   ww  w  .j  av  a  2s.co m*/
 */
@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());
}

From source file:org.selman.tweetamo.TweetamoClient.java

License:Apache License

public static void main(String[] args) throws Exception {

    if (args.length != 2) {
        System.out.println("Usage: [language] [search topic]");
    }//w w w.  ja  va  2  s  .com

    kinesisClient = new AmazonKinesisClient(new ClasspathPropertiesFileCredentialsProvider());
    waitForStreamToBecomeAvailable(STREAM_NAME);

    LOG.info("Publishing tweets to stream : " + STREAM_NAME);
    StatusListener listener = new StatusListener() {
        public void onStatus(Status status) {
            try {
                PutRecordRequest putRecordRequest = new PutRecordRequest();
                putRecordRequest.setStreamName(STREAM_NAME);
                putRecordRequest.setData(TweetSerializer.toBytes(status));
                putRecordRequest.setPartitionKey(status.getUser().getScreenName());
                PutRecordResult putRecordResult = kinesisClient.putRecord(putRecordRequest);
                LOG.info("Successfully putrecord, partition key : " + putRecordRequest.getPartitionKey()
                        + ", ShardID : " + putRecordResult.getShardId());

            } catch (Exception e) {
                LOG.error("Failed to putrecord", e);
            }
        }

        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
        }

        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
        }

        public void onException(Exception ex) {
            ex.printStackTrace();
        }

        @Override
        public void onScrubGeo(long arg0, long arg1) {
        }

        @Override
        public void onStallWarning(StallWarning arg0) {
        }
    };

    ClasspathTwitterCredentialsProvider provider = new ClasspathTwitterCredentialsProvider();
    TwitterCredentials credentials = provider.getTwitterCredentials();

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey(credentials.getConsumerKey())
            .setOAuthConsumerSecret(credentials.getConsumerSecret())
            .setOAuthAccessToken(credentials.getAccessToken())
            .setOAuthAccessTokenSecret(credentials.getAccessTokenSecret());
    TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
    twitterStream.addListener(listener);
    FilterQuery filterQuery = new FilterQuery();
    filterQuery.language(new String[] { args[0] });
    filterQuery.track(new String[] { args[1] });
    twitterStream.filter(filterQuery);
}

From source file:org.shredzone.flufftron.twitter.TwitterFactoryBean.java

License:Open Source License

public TwitterFactoryBean(ConfigurationBuilder cb) {
    factory = new TwitterFactory(cb.build());
}