Example usage for twitter4j.conf ConfigurationBuilder setDebugEnabled

List of usage examples for twitter4j.conf ConfigurationBuilder setDebugEnabled

Introduction

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

Prototype

public ConfigurationBuilder setDebugEnabled(boolean debugEnabled) 

Source Link

Usage

From source file:PrintFirehoseStream.java

License:Apache License

/**
 * Main entry of this application.//  ww  w  . jav a 2 s . com
 *
 * @param args arguments doesn't take effect with this example
 * @throws TwitterException when Twitter service or network is unavailable
 */
public static void main(String[] args) throws TwitterException {

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true);
    cb.setOAuthConsumerKey("");
    cb.setOAuthConsumerSecret("");
    cb.setOAuthAccessToken("");
    cb.setOAuthAccessTokenSecret("");

    TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
    StatusListener listener = new StatusListener() {
        @Override
        public void onStatus(Status status) {
            System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
            System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
        }

        @Override
        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
            System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
        }

        @Override
        public void onScrubGeo(long userId, long upToStatusId) {
            System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
        }

        @Override
        public void onStallWarning(StallWarning warning) {
            System.out.println("Got stall warning:" + warning);
        }

        @Override
        public void onException(Exception ex) {
            ex.printStackTrace();
        }
    };
    twitterStream.addListener(listener);
    twitterStream.firehose(0);
}

From source file:GetLiveMedia.java

License:Open Source License

public void TweetCollect(String searchString) throws TwitterException {
    tXCoord = 0;//from   w w w  . j  av  a  2 s  . c o  m
    tYCoord = 0;
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("0c1v1wqqNATaVcWpINaHoW3o5")
            .setOAuthConsumerSecret("a6sEAJ1NLY3cXhkMTrMZF62bIfww6qLvlEetDAU9O09Mp04lyh")
            .setOAuthAccessToken("330427831-RJig6B6YycJL3xQVoEjjyRaujwnr1xHEQGtSHOOc")
            .setOAuthAccessTokenSecret("Da71qk4SN6Nu88mLkugDDR6CftVcgOcz3QB8dHNw4hVbD");
    TwitterFactory tf = new TwitterFactory(cb.build());
    twitter = tf.getInstance();
    query = new Query("#" + searchString);
    result = twitter.search(query);
    for (Status status : result.getTweets()) {
        try {
            System.out.println(status.getGeoLocation());
            System.out.println(status.getCreatedAt());
            tXCoord = status.getGeoLocation().getLatitude();
            tYCoord = status.getGeoLocation().getLongitude();
            twitterString = ("@" + status.getUser().getScreenName() + ": " + status.getText() + " : " + "("
                    + tXCoord + ", " + tYCoord + ")");
            twitterURL = "https://twitter.com/" + status.getUser().getScreenName() + "/status/"
                    + status.getId();
        } catch (Exception e) {
        }
    }
}

From source file:ac.simons.tweetarchive.config.Twitter4jConfig.java

License:Apache License

@Bean
@ConditionalOnMissingBean//from www  . ja  v a  2s  .c om
public TwitterStreamFactory twitterFactory() {
    final ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(properties.isDebug()).setOAuthConsumerKey(properties.getOauth().getConsumerKey())
            .setOAuthConsumerSecret(properties.getOauth().getConsumerSecret())
            .setOAuthAccessToken(properties.getOauth().getAccessToken())
            .setOAuthAccessTokenSecret(properties.getOauth().getAccessTokenSecret()).setJSONStoreEnabled(true);
    return new TwitterStreamFactory(cb.build());
}

From source file:account.GetRateLimitStatus.java

License:Apache License

public static ConstVars getRateLimit(String[] args) {

    ConstVars StaticVars = new ConstVars();

    try {/*  w w  w . j av a2  s . co m*/

        // init Twitter OAuth
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true).setOAuthConsumerKey(args[1]).setOAuthConsumerSecret(args[2])
                .setOAuthAccessToken(args[3]).setOAuthAccessTokenSecret(args[4]);

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

        // it returns RateLimits of all end-points
        Map<String, RateLimitStatus> rateLimitStatus = twitter.getRateLimitStatus();

        // get RateLimit of required end-point
        RateLimitStatus status = rateLimitStatus.get(args[0]);
        String Endpoint = args[0];
        int Limit = status.getLimit();

        int Remaining = status.getRemaining();
        int ResetTimeInSeconds = status.getResetTimeInSeconds();
        int SecondsUntilReset = status.getSecondsUntilReset();

        // set and return rate limit info to ConstVars's variables
        StaticVars.Endpoint = Endpoint;
        StaticVars.Limit = Limit;
        StaticVars.Remaining = Remaining;
        StaticVars.ResetTimeInSeconds = ResetTimeInSeconds;
        StaticVars.SecondsUntilReset = SecondsUntilReset;

    } catch (TwitterException te) {
        if (args.length == 6) {
            System.err
                    .println("Failed to get rate limit status of " + args[5] + " because: " + te.getMessage());
        } else {
            System.err.println("Failed to get rate limit status because: " + te.getMessage());
        }
    }
    return StaticVars;
}

From source file:adapter.TwitterAllAdapter.java

License:Apache License

public void connectAndRead() throws Exception {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    Properties twitterProperties = new Properties();
    /*File twitter4jPropsFile = new File(System.getProperty("user.home")
    + "/twitter4j.properties");*/
    File twitter4jPropsFile = new File("../twitter4j.properties");
    if (!twitter4jPropsFile.exists()) {
        logger.error("Cannot find twitter4j.properties file in this location :[{}]",
                twitter4jPropsFile.getAbsolutePath());
        return;//  w ww.  ja  v  a 2  s  .c om
    }

    twitterProperties.load(new FileInputStream(twitter4jPropsFile));

    cb = new ConfigurationBuilder();

    cb.setOAuthConsumerKey(twitterProperties.getProperty("oauth.consumerKey"));
    cb.setOAuthConsumerSecret(twitterProperties.getProperty("oauth.consumerSecret"));
    cb.setOAuthAccessToken(twitterProperties.getProperty("oauth.accessToken"));
    cb.setOAuthAccessTokenSecret(twitterProperties.getProperty("oauth.accessTokenSecret"));

    cb.setDebugEnabled(false);
    cb.setPrettyDebugEnabled(false);
    cb.setIncludeMyRetweetEnabled(false);

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

    StatusListener statusListener = new StatusListener() {

        @Override
        public void onException(Exception ex) {
        }

        @Override
        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
        }

        @Override
        public void onStatus(Status status) {
            messageQueue.add(status);
        }

        @Override
        public void onScrubGeo(long userId, long upToStatusId) {
        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
        }

        @Override
        public void onStallWarning(StallWarning arg0) {
        }

    };

    twitterStream.addListener(statusListener);
    twitterStream.sample();

}

From source file:adapter.TwitterKeywordsAdapter.java

License:Apache License

public void connectAndRead() throws Exception {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    Properties twitterProperties = new Properties();
    File twitter4jPropsFile = new File("../twitter4j.properties");
    if (!twitter4jPropsFile.exists()) {
        logger.error("Cannot find twitter4j.properties file in this location :[{}]",
                twitter4jPropsFile.getAbsolutePath());
        return;/*from   w  w  w .  j  a v  a2  s . com*/
    }

    twitterProperties.load(new FileInputStream(twitter4jPropsFile));

    cb = new ConfigurationBuilder();

    cb.setOAuthConsumerKey(twitterProperties.getProperty("oauth.consumerKey"));
    cb.setOAuthConsumerSecret(twitterProperties.getProperty("oauth.consumerSecret"));
    cb.setOAuthAccessToken(twitterProperties.getProperty("oauth.accessToken"));
    cb.setOAuthAccessTokenSecret(twitterProperties.getProperty("oauth.accessTokenSecret"));

    cb.setDebugEnabled(false);
    cb.setPrettyDebugEnabled(false);
    cb.setIncludeMyRetweetEnabled(false);

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

    StatusListener statusListener = new StatusListener() {
        @Override
        public void onException(Exception ex) {
        }

        @Override
        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
        }

        @Override
        public void onStatus(Status status) {
            messageQueue.add(status);
        }

        @Override
        public void onScrubGeo(long userId, long upToStatusId) {
        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
        }

        @Override
        public void onStallWarning(StallWarning arg0) {
        }

    };

    FilterQuery fq = new FilterQuery();

    //System.out.println(Arrays.toString(configuration.getTrack()));

    //Elige todos los tweets que posean esas palabras claves
    fq.track(new String[] { "palabra1,palabra2,palabra3" });
    //fq.track(keywords);
    twitterStream.addListener(statusListener);
    twitterStream.filter(fq);
}

From source file:adapter.TwitterLanguageAdapter.java

License:Apache License

public void connectAndRead() throws Exception {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    Properties twitterProperties = new Properties();
    File twitter4jPropsFile = new File("../twitter4j.properties");
    if (!twitter4jPropsFile.exists()) {
        logger.error("Cannot find twitter4j.properties file in this location :[{}]",
                twitter4jPropsFile.getAbsolutePath());
        return;/* ww w .j a v a  2 s  .  c o  m*/
    }

    twitterProperties.load(new FileInputStream(twitter4jPropsFile));

    cb = new ConfigurationBuilder();

    cb.setOAuthConsumerKey(twitterProperties.getProperty("oauth.consumerKey"));
    cb.setOAuthConsumerSecret(twitterProperties.getProperty("oauth.consumerSecret"));
    cb.setOAuthAccessToken(twitterProperties.getProperty("oauth.accessToken"));
    cb.setOAuthAccessTokenSecret(twitterProperties.getProperty("oauth.accessTokenSecret"));

    cb.setDebugEnabled(false);
    cb.setPrettyDebugEnabled(false);
    cb.setIncludeMyRetweetEnabled(false);

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

    StatusListener statusListener = new StatusListener() {
        @Override
        public void onException(Exception ex) {
        }

        @Override
        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
        }

        @Override
        public void onStatus(Status status) {
            messageQueue.add(status);
        }

        @Override
        public void onScrubGeo(long userId, long upToStatusId) {
        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
        }

        @Override
        public void onStallWarning(StallWarning arg0) {
        }

    };

    //Filter language and track
    FilterQuery tweetFilterQuery = new FilterQuery();
    tweetFilterQuery.track(new String[] { "palabra1,palabra2,palabra3" });
    tweetFilterQuery.language(new String[] { "es" });

    //TwitterStream
    twitterStream.addListener(statusListener);
    twitterStream.filter(tweetFilterQuery);
}

From source file:adapter.TwitterLocationAdapter.java

License:Apache License

public void connectAndRead() throws Exception {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    Properties twitterProperties = new Properties();
    File twitter4jPropsFile = new File("../twitter4j.properties");
    if (!twitter4jPropsFile.exists()) {
        logger.error("Cannot find twitter4j.properties file in this location :[{}]",
                twitter4jPropsFile.getAbsolutePath());
        return;/*from ww w . j  a v  a2 s . c  om*/
    }

    twitterProperties.load(new FileInputStream(twitter4jPropsFile));

    cb = new ConfigurationBuilder();

    cb.setOAuthConsumerKey(twitterProperties.getProperty("oauth.consumerKey"));
    cb.setOAuthConsumerSecret(twitterProperties.getProperty("oauth.consumerSecret"));
    cb.setOAuthAccessToken(twitterProperties.getProperty("oauth.accessToken"));
    cb.setOAuthAccessTokenSecret(twitterProperties.getProperty("oauth.accessTokenSecret"));

    cb.setDebugEnabled(false);
    cb.setPrettyDebugEnabled(false);
    cb.setIncludeMyRetweetEnabled(false);

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

    StatusListener statusListener = new StatusListener() {
        @Override
        public void onException(Exception ex) {
        }

        @Override
        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
        }

        @Override
        public void onStatus(Status status) {
            messageQueue.add(status);
        }

        @Override
        public void onScrubGeo(long userId, long upToStatusId) {
        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
        }

        @Override
        public void onStallWarning(StallWarning arg0) {
        }

    };

    FilterQuery fq = new FilterQuery();
    // Posiciones geogrficas, esas dos coordenadas son el vrtice superior izquierda e inferior derecho
    // de un rectangulo, de tal manera de analizar solo una parte geografica
    double position[][] = { { 0.0, 0.0 }, { 0.0, 0.0 } };
    fq.locations(position);

    twitterStream.addListener(statusListener);
    twitterStream.filter(fq);
}

From source file:android.stickynotes.StickyNotesActivity.java

License:Apache License

private void getTweets(String twit) {
    wifi.setWifiEnabled(true);//from w  w w. j  a v a  2s .  co  m
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("TvywVhWx7r7QQev2UGfA4g")
            .setOAuthConsumerSecret("Nv22zsyf1VS0vvi6hwAMyvJk9LUtSXwRUB4xwp2gRs");
    TwitterFactory tf = new TwitterFactory(cb.build());
    Twitter twitter = tf.getInstance();
    try {
        QueryResult result = twitter.search(new Query(twit));
        List<Tweet> tweets = result.getTweets();
        textStatus.setText("");
        textStatus.append("Recent tweets about '" + twit + "':\n");
        for (Tweet tweet : tweets) {
            textStatus.append("@" + tweet.getFromUser() + " - " + tweet.getText() + "\n\n");
        }
    } catch (TwitterException te) {
        te.printStackTrace();
        textStatus.append("Failed to search tweets: " + te.getMessage() + " " + twit);
    }
}

From source file:apptwitter.Metodos.java

public Metodos() {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("5yqwH2WcqZ3YlkE0W8BLYkeoW")
            .setOAuthConsumerSecret("s5s5QGigqzULDGbbQs4Rm0pKdqLEefbO4gCh53XgcnA0RoMA9n")
            .setOAuthAccessToken("3055143533-jeaPEtFscvDMVKwPVLubxkmHs9DzCjZ2eIoWdcQ")
            .setOAuthAccessTokenSecret("NzIM687NlVRe3VxKh0a0xRRYpsGytrSEKISaqpuQGtTZL");

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