Example usage for twitter4j.conf ConfigurationBuilder setJSONStoreEnabled

List of usage examples for twitter4j.conf ConfigurationBuilder setJSONStoreEnabled

Introduction

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

Prototype

public ConfigurationBuilder setJSONStoreEnabled(boolean enabled) 

Source Link

Usage

From source file:d3V.GetFriendsIDs.java

License:Apache License

/**
 * Usage: java twitter4j.examples.friendsandfollowers.GetFollowersIDs [screen name]
 *
 * @param args message/*ww w.  ja  v a 2  s . co  m*/
 */
public static void main(String[] args) {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("Em3WTI7jc90HcvKzPkTLQ")
            .setOAuthConsumerSecret("vg4p6rOF32bmffqRR8m0jAUClrxvtGiMB5PrSr3Zsw")
            .setOAuthAccessToken("1681973072-1q0zI0VPjHD3ttNuaBOL94frzCI9sXInxAcDK0w")
            .setOAuthAccessTokenSecret("ZRLkOyjmhHBkU1iNyEVNyIgIBsKrl0DUDKOcOMneYFYEM");
    cb.setJSONStoreEnabled(true);

    TwitterFactory tf = new TwitterFactory(cb.build());
    try {
        String core_user = "nytimes";
        FileWriter writer = new FileWriter(core_user + "_friends.txt", true);
        Twitter twitter = tf.getInstance();

        long cursor = -1;
        ArrayList<String> directFriends = new ArrayList<String>();
        PagableResponseList<User> tempFriends = null;

        System.out.println("Listing " + core_user + " friends's ScreenNames.");
        int count = 0;
        //boolean first = true;
        //getFriends(writer, twitter, cursor, count, core_user);
        do {
            tempFriends = twitter.getFriendsList(core_user, cursor);

            for (User user : tempFriends) {
                directFriends.add(user.getScreenName());
                writer.write(core_user + "\t" + user.getScreenName() + "\n");
            }

            count += tempFriends.size();
            System.out.println(core_user + ": " + count);
            if (count >= 100)
                break;

            Thread.sleep(300 * MILLISECOND);

        } while ((cursor = tempFriends.getNextCursor()) != 0);

        System.out.println("Size of DFs: " + directFriends.size());

        //            for (String user : directFriends){
        for (int i = 0; i < directFriends.size(); i++) {
            //                PagableResponseList<User> idrfriends = null;
            long _cursor = -1;
            int _count = 0;
            String _username = directFriends.get(i);
            System.out.println("\nFriends of Direct friend: " + _username + "(" + (i + 1) + ")");
            try {
                getFriends(writer, twitter, _cursor, _count, _username);
            } catch (TwitterException e) {
                e.printStackTrace();
                System.out.println("Failed to get friends' ids: " + e.getMessage());
            } catch (IOException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }

        writer.close();
        System.out.println(count);
        System.exit(0);
    } catch (TwitterException e) {
        e.printStackTrace();
        System.out.println("Failed to get friends' ids: " + e.getMessage());
        System.exit(-1);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:de.fhb.twitalyse.spout.TwitterStreamSpout.java

License:Open Source License

@Override
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
    this.collector = collector;

    // enable JSONStore
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setJSONStoreEnabled(true);

    TwitterStreamFactory twitterStreamFactory = new TwitterStreamFactory(cb.build());
    twitterStream = twitterStreamFactory.getInstance();

    AccessToken givenAccessToken = new AccessToken(TOKEN, TOKEN_SECRET);
    twitterStream.setOAuthConsumer(CONSUMER_KEY, CONSUMER_KEY_SECURE);
    twitterStream.setOAuthAccessToken(givenAccessToken);
    twitterStream.addListener(this);
    twitterStream.sample();//from   ww w .j av  a  2 s .  co  m
}

From source file:de.fhm.bigdata.projekt.dataimport.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  a v  a 2 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);

    proxyEnabled = context.getBoolean(TwitterSourceConstants.PROXY_ENABLED);
    proxyHost = context.getString(TwitterSourceConstants.PROXY_HOST);
    proxyPort = context.getInteger(TwitterSourceConstants.PROXY_PORT);

    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();
        }
    }

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

    if (proxyEnabled) {
        cb.setHttpProxyHost(proxyHost);
        cb.setHttpProxyPort(proxyPort);//port
    }

    twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
}

From source file:oauth.AppOAuth.java

License:Apache License

public TwitterFactory loadOAuthUser(String endpoint)
        throws ClassNotFoundException, SQLException, TwitterException {

    MysqlDB DB = new MysqlDB();
    // System.out.println("DEBUG AppOAuth.java");

    // get OAuth cradentials by calling DB's loadOAuthUser(endpoint)
    ConstVars StaticVars = DB.loadOAuthUser(endpoint);

    String consumer_key = StaticVars.consumer_key;
    String consumer_secret = StaticVars.consumer_secret;
    String user_token = StaticVars.user_token;
    String user_secret = StaticVars.user_secret;

    RemainingCalls = StaticVars.Remaining;
    screen_name = StaticVars.screen_name;

    // working with twitter4j.properties
    // Twitter twitter = new TwitterFactory().getInstance(); 
    // initialize Twitter OAuth
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setJSONStoreEnabled(true).setDebugEnabled(true).setOAuthConsumerKey(consumer_key)
            .setOAuthConsumerSecret(consumer_secret).setOAuthAccessToken(user_token)
            .setOAuthAccessTokenSecret(user_secret);

    TwitterFactory tf = new TwitterFactory(cb.build());
    return tf;//from w ww. j a  v a 2s.  c o  m
}

From source file:oauth.AppOAuth.java

License:Apache License

public TwitterFactory loadOAuthUser(String endpoint, int TOTAL_JOBS, int JOB_NO)
        throws ClassNotFoundException, SQLException, TwitterException {

    MysqlDB DB = new MysqlDB();

    // System.out.println("DEBUG AppOAuth.java");
    // get OAuth cradentials by calling DB's loadOAuthUser(endpoint)
    ConstVars StaticVars = DB.loadOAuthUser(endpoint, TOTAL_JOBS, JOB_NO);

    String consumer_key = StaticVars.consumer_key;
    String consumer_secret = StaticVars.consumer_secret;
    String user_token = StaticVars.user_token;
    String user_secret = StaticVars.user_secret;

    RemainingCalls = StaticVars.Remaining;
    screen_name = StaticVars.screen_name;

    // working with twitter4j.properties
    // Twitter twitter = new TwitterFactory().getInstance(); 
    // initialize Twitter OAuth
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setJSONStoreEnabled(true).setDebugEnabled(true).setOAuthConsumerKey(consumer_key)
            .setOAuthConsumerSecret(consumer_secret).setOAuthAccessToken(user_token)
            .setOAuthAccessTokenSecret(user_secret);

    TwitterFactory tf = new TwitterFactory(cb.build());
    return tf;//from w  ww . j a v a 2 s .  c o m
}

From source file:oauth.AppOAuth.java

License:Apache License

public TwitterFactory loadOAuthUser(String endpoint, String consumer_key, String consumer_secret,
        String user_token, String user_secret) throws ClassNotFoundException, SQLException, TwitterException {

    // Send OAuth credentials and get rate limit of endpoint
    String[] args = { endpoint, consumer_key, consumer_secret, user_token, user_secret };
    StaticVars = GetRateLimitStatus.getRateLimit(args);

    RemainingCalls = StaticVars.Remaining;

    // working with twitter4j.properties
    // Twitter twitter = new TwitterFactory().getInstance(); 
    // initialize Twitter OAuth
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setJSONStoreEnabled(true).setDebugEnabled(true).setOAuthConsumerKey(consumer_key)
            .setOAuthConsumerSecret(consumer_secret).setOAuthAccessToken(user_token)
            .setOAuthAccessTokenSecret(user_secret);

    TwitterFactory tf = new TwitterFactory(cb.build());
    return tf;//from  ww  w . j av  a 2  s.  c o  m
}

From source file:OAuth.MyOwnTwitterFactory.java

License:Open Source License

public TwitterStream createOneTwitterStreamInstance(AccessToken accessToken) {
    TwitterStream twitterStream;/*w  w w.jav 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 .  ja v  a 2 s. c  o  m
    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:org.elasticsearch.river.twitter.TwitterRiver.java

License:Apache License

/**
 * Twitter Stream Builder/*  ww w . ja v  a2 s  .c  o m*/
 * @return
 */
private TwitterStream buildTwitterStream() {
    logger.debug("creating TwitterStreamFactory");
    ConfigurationBuilder cb = new ConfigurationBuilder();

    cb.setOAuthConsumerKey(oauthConsumerKey).setOAuthConsumerSecret(oauthConsumerSecret)
            .setOAuthAccessToken(oauthAccessToken).setOAuthAccessTokenSecret(oauthAccessTokenSecret);

    if (proxyHost != null)
        cb.setHttpProxyHost(proxyHost);
    if (proxyPort != null)
        cb.setHttpProxyPort(Integer.parseInt(proxyPort));
    if (proxyUser != null)
        cb.setHttpProxyUser(proxyUser);
    if (proxyPassword != null)
        cb.setHttpProxyPassword(proxyPassword);
    if (raw)
        cb.setJSONStoreEnabled(true);

    // We force SSL usage
    cb.setUseSSL(true);

    TwitterStream stream = new TwitterStreamFactory(cb.build()).getInstance();
    stream.addListener(new StatusHandler());

    return stream;
}

From source file:org.loklak.harvester.TwitterAPI.java

License:Open Source License

private static TwitterFactory getUserTwitterFactory(String accessToken, String accessTokenSecret) {
    if (accessToken == null || accessToken.length() == 0 || accessTokenSecret == null
            || accessTokenSecret.length() == 0)
        return null;
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setOAuthConsumerKey(DAO.getConfig("client.twitterConsumerKey", ""))
            .setOAuthConsumerSecret(DAO.getConfig("client.twitterConsumerSecret", ""))
            .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessTokenSecret);
    cb.setJSONStoreEnabled(true);
    return new TwitterFactory(cb.build());
}