Example usage for twitter4j.conf ConfigurationBuilder setOAuthConsumerKey

List of usage examples for twitter4j.conf ConfigurationBuilder setOAuthConsumerKey

Introduction

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

Prototype

public ConfigurationBuilder setOAuthConsumerKey(String oAuthConsumerKey) 

Source Link

Usage

From source file:net.wasdev.gameon.auth.twitter.TwitterCallback.java

License:Apache License

/**
 * Method that performs introspection on an AUTH string, and returns data as
 * a String->String hashmap./* w  ww . java2  s  . c  om*/
 * 
 * @param auth
 *            the authstring to query, as built by an auth impl.
 * @return the data from the introspect, in a map.
 * @throws IOException
 *             if anything goes wrong.
 */
public Map<String, String> introspectAuth(String token, String tokensecret) throws IOException {
    Map<String, String> results = new HashMap<String, String>();

    ConfigurationBuilder c = new ConfigurationBuilder();
    c.setOAuthConsumerKey(key).setOAuthConsumerSecret(secret).setOAuthAccessToken(token)
            .setOAuthAccessTokenSecret(tokensecret);

    Twitter twitter = new TwitterFactory(c.build()).getInstance();

    try {
        // ask twitter to verify the token & tokensecret from the auth
        // string
        // if invalid, it'll throw a TwitterException
        twitter.verifyCredentials();

        // if it's valid, lets grab a little more info about the user.
        long id = twitter.getId();
        ResponseList<User> users = twitter.lookupUsers(id);
        User u = users.get(0);
        String name = u.getName();
        String screenname = u.getScreenName();

        results.put("valid", "true");
        results.put("id", "twitter:" + id);
        results.put("name", name);
        results.put("screenname", screenname);

    } catch (TwitterException e) {
        results.put("valid", "false");
    }

    return results;
}

From source file:OAuth.MyOwnTwitterFactory.java

License:Open Source License

public Twitter createOneTwitterInstance() {
    Twitter twitter;/*w w w .ja v  a 2 s.co m*/
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(APIkeys.getTwitterAPIKey());
    builder.setOAuthConsumerSecret(APIkeys.getTwitterAPISecret());
    builder.setOAuthAccessToken("31805620-QQy8TFFDKRxWyOUVnY08UcxT5bzrFhRWUa0A3lEW3");
    builder.setOAuthAccessTokenSecret("iJuCkdgrfIpGn5odyF2evMSvAsovreeEV6cZU5ihVVI7j");
    Configuration configuration = builder.build();
    TwitterFactory factory = new TwitterFactory(configuration);
    twitter = factory.getInstance();

    return twitter;

}

From source file:OAuth.MyOwnTwitterFactory.java

License:Open Source License

public TwitterStream createOneTwitterStreamInstance(AccessToken accessToken) {
    TwitterStream twitterStream;/*w  w  w. ja v a  2  s.  c  o  m*/
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(APIkeys.getTwitterAPIKey());
    builder.setOAuthConsumerSecret(APIkeys.getTwitterAPISecret());
    System.out.println("AT: " + accessToken.getToken());
    System.out.println("ATS: " + accessToken.getTokenSecret());
    builder.setOAuthAccessToken(accessToken.getToken());
    builder.setOAuthAccessTokenSecret(accessToken.getTokenSecret());
    builder.setJSONStoreEnabled(true);
    //        builder.setOAuthAccessToken("31805620-QQy8TFFDKRxWyOUVnY08UcxT5bzrFhRWUa0A3lEW3");
    //        builder.setOAuthAccessTokenSecret("iJuCkdgrfIpGn5odyF2evMSvAsovreeEV6cZU5ihVVI7j");
    Configuration configuration = builder.build();
    TwitterStreamFactory factory = new TwitterStreamFactory(configuration);
    twitterStream = factory.getInstance();

    return twitterStream;
}

From source file:OAuth.MyOwnTwitterFactory.java

License:Open Source License

public TwitterStream createOneTwitterStreamInstanceFromApp(String APIKey, String APIKeySecret,
        String accessToken, String accessTokenSecret) {
    TwitterStream twitterStream;//from w  w w.j av  a2  s  . c om
    ConfigurationBuilder builder = new ConfigurationBuilder();
    if (!Admin.isTest()) {
        builder.setOAuthConsumerKey(APIKey);
        builder.setOAuthConsumerSecret(APIKeySecret);
        builder.setOAuthAccessToken(accessToken);
        builder.setOAuthAccessTokenSecret(accessTokenSecret);
        builder.setJSONStoreEnabled(true);
    } else {
        builder.setOAuthConsumerKey("KNjw1QTK1hJKx8LpK6X6rg");
        builder.setOAuthConsumerSecret("ikX9blowuh3FqFAkIg5LQi5voLOV413EWzPsDl77uU");
        builder.setOAuthAccessToken("31805620-QQy8TFFDKRxWyOUVnY08UcxT5bzrFhRWUa0A3lEW3");
        builder.setOAuthAccessTokenSecret("iJuCkdgrfIpGn5odyF2evMSvAsovreeEV6cZU5ihVVI7j");
        builder.setJSONStoreEnabled(true);
    }
    Configuration configuration = builder.build();
    TwitterStreamFactory factory = new TwitterStreamFactory(configuration);
    twitterStream = factory.getInstance();

    return twitterStream;
}

From source file:ontoSentiment.Util.java

public static OAuth2Token getOAuth2Token() {
    OAuth2Token token = null;//from   w  w w  . jav a2  s  .  co  m
    ConfigurationBuilder cb;
    cb = new ConfigurationBuilder();
    cb.setApplicationOnlyAuthEnabled(true);
    cb.setOAuthConsumerKey(CONSUMER_KEY).setOAuthConsumerSecret(CONSUMER_SECRET);
    try {
        token = new TwitterFactory(cb.build()).getInstance().getOAuth2Token();
    } catch (Exception e) {
        System.out.println("Could not get OAuth2 token");
        e.printStackTrace();
        System.exit(0);
    }
    return token;
}

From source file:ontoSentiment.Util.java

public static Twitter getTwitter() {
    OAuth2Token token;/* ww  w .  j  av a 2 s  .com*/
    token = getOAuth2Token();
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setApplicationOnlyAuthEnabled(true);
    cb.setOAuthConsumerKey(CONSUMER_KEY);
    cb.setOAuthConsumerSecret(CONSUMER_SECRET);
    cb.setOAuth2TokenType(token.getTokenType());
    cb.setOAuth2AccessToken(token.getAccessToken());
    return new TwitterFactory(cb.build()).getInstance();
}

From source file:org.addhen.smssync.data.twitter.TwitterClient.java

License:Open Source License

private void initTwitterFactory() {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(mAuthConfig.consumerKey);
    builder.setOAuthConsumerSecret(mAuthConfig.consumerSecret);
    mTwitterFactory = new TwitterFactory(builder.build());

}

From source file:org.apache.camel.component.twitter.TwitterConfiguration.java

License:Apache License

/**
 * Builds a Twitter4J Configuration using the OAuth params.
 *
 * @return Configuration// ww w .java 2s .c om
 */
public Configuration getConfiguration() {
    checkComplete();
    ConfigurationBuilder confBuilder = new ConfigurationBuilder();
    confBuilder.setOAuthConsumerKey(consumerKey);
    confBuilder.setOAuthConsumerSecret(consumerSecret);
    confBuilder.setOAuthAccessToken(accessToken);
    confBuilder.setOAuthAccessTokenSecret(accessTokenSecret);
    confBuilder.setUseSSL(useSSL);
    if (getHttpProxyHost() != null) {
        confBuilder.setHttpProxyHost(getHttpProxyHost());
    }
    if (getHttpProxyUser() != null) {
        confBuilder.setHttpProxyHost(getHttpProxyUser());
    }
    if (getHttpProxyPassword() != null) {
        confBuilder.setHttpProxyHost(getHttpProxyPassword());
    }
    if (httpProxyPort != null) {
        confBuilder.setHttpProxyPort(httpProxyPort);
    }

    return confBuilder.build();
}

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;/* w ww . ja  va 2s .  c  o  m*/

    logConfig();
}

From source file:org.botlibre.sense.twitter.Twitter.java

License:Open Source License

public void connect() throws TwitterException {
    initProperties();//ww  w.  j a  va  2  s  .  c  o  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);
}