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.smarttechie.servlet.SimpleStream.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String keywords = request.getParameter("keywords");
    SEARCH_NAME = request.getParameter("SearchName");
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true);/*  w  w w  .j  a  v a 2  s  .c  om*/
    cb.setOAuthConsumerKey("Y8NvcZqWjUvNR0wfict2rSKmx");
    cb.setOAuthConsumerSecret("A3K8YqVjLpTN5sSbk9MJ8DmiwIxRapLmyhmZcCau55sqzPjA1y");
    cb.setOAuthAccessToken("566064066-BMF8JBt2JI7c4KBWEDtxRqPN2rLNxwKcUoykzoTR");
    cb.setOAuthAccessTokenSecret("wo4LnwlsYYfbYkGixN0CS3NxlYfXxbxwl0gWfpQTIKas4");
    //PrintStream out = new PrintStream(new FileOutputStream("/home/mary/Documents/Tesis/output.txt"));
    //System.setOut(out);
    Cluster cluster;
    Session session;
    cluster = Cluster.builder().addContactPoint("localhost").build();
    session = cluster.connect("GetTheLead");
    String[] parametros = { keywords };
    twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
    //EmbeddedNeo4j neo = new EmbeddedNeo4j();
    //neo.createDb();
    //neo.removeData();
    //neo.shutDown();
    graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
    registerShutdownHook(graphDb);
    getStream(twitterStream, parametros, session);//,out);
    //out.close();

}

From source file:org.smarttechie.servlet.TwitterLoginServlet.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    System.out.println("TwitterLoginServlet:doGet");
    ConfigurationBuilder cb = new ConfigurationBuilder();

    Properties props = new TwitterProperties().getProperties();
    cb.setDebugEnabled(true).setOAuthConsumerKey((String) props.get("twitterConsumerKey"))
            .setOAuthConsumerSecret((String) props.get("twitterConsumerSecret"))
            .setOAuthRequestTokenURL((String) props.get("twitterRequestTokenURL"))
            .setOAuthAuthorizationURL((String) props.get("twitterAuthorizeURL"))
            .setOAuthAccessTokenURL((String) props.get("twitterAccessTokenURL"));
    TwitterFactory tf = new TwitterFactory(cb.build());
    Twitter twitter = tf.getInstance();/*from ww w. ja va  2  s . c o m*/
    request.getSession().setAttribute("twitter", twitter);
    try {
        StringBuffer callbackURL = request.getRequestURL();
        System.out.println("TwitterLoginServlet:callbackURL:" + callbackURL);
        int index = callbackURL.lastIndexOf("/");
        callbackURL.replace(index, callbackURL.length(), "").append("/TwitterCallback");

        RequestToken requestToken = twitter.getOAuthRequestToken(callbackURL.toString());
        request.getSession().setAttribute("requestToken", requestToken);
        System.out.println("requestToken.getAuthenticationURL():" + requestToken.getAuthenticationURL());
        response.sendRedirect(requestToken.getAuthenticationURL());

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

}

From source file:org.socialnetlib.android.TwitterApi.java

License:Apache License

Twitter getAndConfigureApiInstance() {

    if (mCurrentOAuthToken == null || mCurrentOAuthSecret == null) {
        mSocNetApi = null;//from w w w . j  a v  a  2  s.  c  o m
        mOAuth = null;
    } else if (mSocNetApi == null) {

        ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
        configurationBuilder.setDebugEnabled(true).setOAuthConsumerKey(mAppConsumerKey)
                .setOAuthConsumerSecret(mAppConsumerSecret).setOAuthAccessToken(mCurrentOAuthToken)
                .setOAuthAccessTokenSecret(mCurrentOAuthSecret).setMediaProvider("TWITTER")
                // .setJSONStoreEnabled(true)
                .setIncludeEntitiesEnabled(true);

        Configuration configuration = configurationBuilder.build();
        mSocNetApi = new TwitterFactory(configuration).getInstance();
        // mOAuth = new
        // TwitterFactory(configuration).getOAuthAuthorization();
    }
    return mSocNetApi;
}

From source file:org.sociotech.communitymashup.source.twitter.TwitterSourceService.java

License:Open Source License

/**
 * Establishes a connection with twitter based on the user information given
 * in the configuration./*from   w w  w.ja  v  a  2  s  . c  o m*/
 * 
 * @return True if it is possible to use the user information for the
 *         connection, false otherwise.
 */
private boolean establishConnection() {

    // get property values from configuration
    String consumerKey = source.getPropertyValue(TwitterProperties.CONSUMER_KEY_PROPERTY);
    String consumerSecret = source.getPropertyValue(TwitterProperties.CONSUMER_SECRET_PROPERTY);
    String accessTokenValue = source.getPropertyValue(TwitterProperties.ACCESS_TOKEN_PROPERTY);
    String accessTokenSecret = source.getPropertyValue(TwitterProperties.ACCESS_TOKEN_SECRET_PROPERTY);

    // check properties
    if (consumerKey == null || consumerKey.isEmpty()) {
        log("A valid consumer key is needed in the configuration specified by "
                + TwitterProperties.CONSUMER_KEY_PROPERTY, LogService.LOG_WARNING);
        return false;
    } else if (consumerSecret == null || consumerSecret.isEmpty()) {
        log("A valid consumer secret is needed in the configuration specified by "
                + TwitterProperties.CONSUMER_SECRET_PROPERTY, LogService.LOG_WARNING);
        return false;
    } else if (accessTokenValue == null || accessTokenValue.isEmpty()) {
        log("A valid access token is needed in the configuration specified by "
                + TwitterProperties.ACCESS_TOKEN_PROPERTY, LogService.LOG_WARNING);
        return false;
    } else if (accessTokenSecret == null || accessTokenSecret.isEmpty()) {
        log("A valid token secret is needed in the configuration specified by "
                + TwitterProperties.ACCESS_TOKEN_SECRET_PROPERTY, LogService.LOG_WARNING);
        return false;
    }

    // get access with the provided credencials
    // TODO disable debug
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret)
            .setOAuthAccessToken(accessTokenValue).setOAuthAccessTokenSecret(accessTokenSecret);

    TwitterFactory tf = new TwitterFactory(cb.build());

    twitterAPI = tf.getInstance();

    if (twitterAPI == null) {
        log("Could not create a connection to the twitter api!", LogService.LOG_ERROR);
    }

    return true;
}

From source file:org.structr.web.auth.TwitterAuthClient.java

License:Open Source License

@Override
protected void init(final String authorizationLocation, final String tokenLocation, final String clientId,
        final String clientSecret, final String redirectUri, final Class tokenResponseClass) {

    super.init(authorizationLocation, tokenLocation, clientId, clientSecret, redirectUri, tokenResponseClass);

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setOAuthAuthorizationURL(authorizationLocation);
    cb.setOAuthAccessTokenURL(tokenLocation);

    Configuration conf = cb.build();

    TwitterFactory tf = new TwitterFactory(conf);
    twitter = tf.getInstance();/*from   www . j a v a  2s. c  o  m*/
    twitter.setOAuthConsumer(clientId, clientSecret);

}

From source file:org.talend.spark.operation.TwitterLoad.java

License:Open Source License

public static JavaDStream<List<Object>> twitterStream(JavaStreamingContext ctx, String username,
        String password, String accessToken, String secretToken, String[] filters,
        List<TwitterParameter> twitterParameters) {
    twitter4j.conf.ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthAccessToken(accessToken);
    builder.setOAuthAccessTokenSecret(secretToken);
    builder.setOAuthConsumerKey(username);
    builder.setOAuthConsumerSecret(password);
    JavaDStream<Status> inputDStream = null;
    if (filters.length > 0) {
        if (filters.length == 1 && filters[0].equals(""))
            inputDStream = TwitterUtils.createStream(ctx, new OAuthAuthorization(builder.build()));
        else//from  www. j a va2 s  .co  m
            inputDStream = TwitterUtils.createStream(ctx, new OAuthAuthorization(builder.build()), filters);

        return inputDStream.map(new LoadTwitterFunction(twitterParameters));
    }
    return null;
}

From source file:org.threeriverdev.twitterreporter.TwitterBot.java

License:Apache License

public static void main(String... args) throws Exception {
    FilterQuery query = new FilterQuery();
    List<double[]> locations = new ArrayList<double[]>();

    // Create a grid over the continental US.
    // TODO: Originally (2009ish), these were recommended by Twitter.  Not sure if it's relevant now or not --
    // could we achieve the same results with 1 big block?
    for (double swLat = 25.0; swLat <= 49.0; swLat = swLat + GRIDSIZE) {
        for (double swLon = -125.0; swLon <= -67.0; swLon = swLon + GRIDSIZE) {
            double neLat = swLat + GRIDSIZE;
            double neLon = swLon + GRIDSIZE;

            double[] swLocation = new double[2];
            swLocation[0] = swLon;/*  ww  w .  j  a v  a2  s. com*/
            swLocation[1] = swLat;
            locations.add(swLocation);

            double[] neLocation = new double[2];
            neLocation[0] = neLon;
            neLocation[1] = neLat;
            locations.add(neLocation);
        }
    }

    query.locations(locations.toArray(new double[0][0]));

    try {
        URL url = TwitterBot.class.getResource("/oauth.properties");
        Properties p = new Properties();
        InputStream inStream = url.openStream();
        p.load(inStream);

        ConfigurationBuilder confBuilder = new ConfigurationBuilder();
        confBuilder.setOAuthConsumerKey(p.getProperty("consumer.key"));
        confBuilder.setOAuthConsumerSecret(p.getProperty("consumer.secret"));
        confBuilder.setOAuthAccessToken(p.getProperty("access.token"));
        confBuilder.setOAuthAccessTokenSecret(p.getProperty("access.token.secret"));
        Configuration conf = confBuilder.build();

        TwitterStream twitterStream = new TwitterStreamFactory(conf).getInstance();
        twitterStream.addListener(new TweetProcessor());
        twitterStream.filter(query);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.twitter.sample.main.Stream.java

public void getTweetsFromTwitter() {

    StatusListener listener = new StatusListener() {
        private boolean logQueueFull = true;

        @Override//from  w  w  w. j  av  a 2  s.co m
        public void onException(Exception e) {
            log.error(e);
        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice notice) {
        }

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

        @Override
        public void onStatus(Status status) {
            db.insert(status);
        }

        @Override
        public void onTrackLimitationNotice(int notice) {
            log.warn("*** TRACK LIMITATION REACHED: " + notice + " ***");
        }

        @Override
        public void onStallWarning(StallWarning arg0) {
            log.warn("*** STALL WARNING: " + arg0);
        }
    };

    ConfigurationBuilder twitterConfig = new ConfigurationBuilder();
    twitterConfig.setDebugEnabled(false);
    twitterConfig.setOAuthAccessTokenSecret(access_token_secret);
    twitterConfig.setOAuthAccessToken(access_token);
    twitterConfig.setOAuthConsumerKey(consumer_key);
    twitterConfig.setOAuthConsumerSecret(consumer_secret);
    twitterConfig.setJSONStoreEnabled(true);

    TwitterStreamFactory fact = new TwitterStreamFactory(twitterConfig.build());
    this.twitterStream = fact.getInstance();
    this.twitterStream.addListener(listener);
    FilterQuery filterQuery = new FilterQuery();
    filterQuery.language(new String[] { "en" });
    this.twitterStream.filter(filterQuery);
    this.twitterStream.sample();

}

From source file:org.uma.jmetalsp.application.biobjectivetsp.sparkutil.StreamingConfigurationTSP.java

License:Open Source License

/**
 * Create Twitter configuration/*  w w  w .  j a  v  a 2 s .c  o m*/
 * @param consumerKey
 * @param consumerSecret
 * @param accessToken
 * @param accessTokenSecret
 * @param proxyHost
 * @param proxyPort
 * @param twitterFilter
 */
public void initializeTwitter(String consumerKey, String consumerSecret, String accessToken,
        String accessTokenSecret, String proxyHost, int proxyPort, String twitterFilter) {
    this.twitterFilter = twitterFilter;
    ConfigurationBuilder cb = new ConfigurationBuilder();
    if (proxyHost != null) {
        System.setProperty("http.proxyHost", proxyHost);
        System.setProperty("http.proxyPort", String.valueOf(proxyPort));
        System.setProperty("https.proxyHost", proxyHost);
        System.setProperty("https.proxyPort", String.valueOf(proxyPort));
    }
    cb.setDebugEnabled(true).setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret)
            .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessTokenSecret);
    Configuration twitterConf = cb.build();

    twitterAuth = AuthorizationFactory.getInstance(twitterConf);
}

From source file:org.voiser.zoe.TwitterAgent.java

License:MIT License

/**
 * /*w w w .ja  v  a 2 s  .  com*/
 */
public TwitterAgent() {
    String consumerKey = System.getenv("zoe_twitter_consumer_key");
    String consumerSecret = System.getenv("zoe_twitter_consumer_secret");
    String accessToken = System.getenv("zoe_twitter_access_token");
    String accessTokenSecret = System.getenv("zoe_twitter_access_token_secret");

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

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