Example usage for twitter4j.conf ConfigurationBuilder setOAuthAccessToken

List of usage examples for twitter4j.conf ConfigurationBuilder setOAuthAccessToken

Introduction

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

Prototype

public ConfigurationBuilder setOAuthAccessToken(String oAuthAccessToken) 

Source Link

Usage

From source file:org.jraf.irondad.handler.twitter.follow.TwitterFollowHandler.java

License:Open Source License

private static Twitter getTwitter(HandlerContext handlerContext) {
    Twitter res = (Twitter) handlerContext.get("twitter");
    if (res == null) {
        TwitterFollowHandlerConfig twitterFollowHandlerConfig = (TwitterFollowHandlerConfig) handlerContext
                .getHandlerConfig();//  w w w .j  av a2 s  .  co m
        ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
        configurationBuilder.setDebugEnabled(true)
                .setOAuthConsumerKey(twitterFollowHandlerConfig.getOauthConsumerKey());
        configurationBuilder.setOAuthConsumerSecret(twitterFollowHandlerConfig.getOauthConsumerSecret());
        configurationBuilder.setOAuthAccessToken(twitterFollowHandlerConfig.getOauthAccessToken());
        configurationBuilder.setOAuthAccessTokenSecret(twitterFollowHandlerConfig.getOauthAccessTokenSecret());
        TwitterFactory twitterFactory = new TwitterFactory(configurationBuilder.build());
        res = twitterFactory.getInstance();

        handlerContext.put("twitter", res);
    }
    return res;
}

From source file:org.jraf.irondad.handler.twitter.links.TwitterLinksHandler.java

License:Open Source License

private static Twitter getTwitter(HandlerContext handlerContext) {
    Twitter res = (Twitter) handlerContext.get("twitter");
    if (res == null) {
        TwitterLinksHandlerConfig twitterLinksHandlerConfig = (TwitterLinksHandlerConfig) handlerContext
                .getHandlerConfig();//from   www  .j ava2 s .  c om
        ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
        configurationBuilder.setDebugEnabled(true)
                .setOAuthConsumerKey(twitterLinksHandlerConfig.getOauthConsumerKey());
        configurationBuilder.setOAuthConsumerSecret(twitterLinksHandlerConfig.getOauthConsumerSecret());
        configurationBuilder.setOAuthAccessToken(twitterLinksHandlerConfig.getOauthAccessToken());
        configurationBuilder.setOAuthAccessTokenSecret(twitterLinksHandlerConfig.getOauthAccessTokenSecret());
        TwitterFactory twitterFactory = new TwitterFactory(configurationBuilder.build());
        res = twitterFactory.getInstance();

        handlerContext.put("twitter", res);
    }
    return res;
}

From source file:org.mule.twitter.TwitterConnector.java

License:Open Source License

private TwitterStream newStream() {
    ConfigurationBuilder cb = new ConfigurationBuilder().setUseSSL(useSSL).setOAuthConsumerKey(consumerKey)
            .setOAuthConsumerSecret(consumerSecret).setStreamBaseURL(getStreamBaseUrl())
            .setSiteStreamBaseURL(getSiteStreamBaseUrl()).setHttpProxyHost(proxyHost)
            .setHttpProxyPort(proxyPort).setHttpProxyUser(proxyUsername).setHttpProxyPassword(proxyPassword);

    if (getAccessToken() != null) {
        cb.setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessTokenSecret);
    }// ww  w .j av a  2 s.  c om

    HttpClientHiddenConstructionArgument.setUseMule(false);
    return new TwitterStreamFactory(cb.build()).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.
 *//*  ww w.j av a2 s.c om*/
@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.primeoservices.cfgateway.twitter.railo.RailoTwitterUserStreamGateway.java

License:Apache License

/**
 * Initializes this gateway//from w  w  w.  j a  va 2  s.  c o 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.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);/* ww  w . j  ava2s .c o  m*/
    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.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  av a  2s . c  o 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;// w  w  w . ja  v a2s .  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/*ww w.  j  av  a 2 s  .  c  o  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();

}