Example usage for twitter4j.conf ConfigurationBuilder ConfigurationBuilder

List of usage examples for twitter4j.conf ConfigurationBuilder ConfigurationBuilder

Introduction

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

Prototype

ConfigurationBuilder

Source Link

Usage

From source file:dhbw.clippinggorilla.external.twitter.TwitterUtils.java

/**
 * Configures Twitter API Keys/*w w w .  j a  v  a 2 s . c  o  m*/
 */
public static void config() {
    if (tf == null) {
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true)
                .setOAuthConsumerKey(Props.getOrDefault("OAuthConsumerKey", "8MEY2XDvYPblVVQgFdSzSrydQ"))
                .setOAuthConsumerSecret(Props.getOrDefault("OAuthConsumerSecret",
                        "IpKkXw2gvfJCEwjGv2Yz5LwRv0Zn1B9nMLkQVleldyhdVPgPVj"))
                .setOAuthAccessToken(Props.getOrDefault("OAuthAccessToken",
                        "2646251996-E0Glh4yG12AyJ6DM7PCy9sTKhs0w8gP4yCFFvU2"))
                .setOAuthAccessTokenSecret(Props.getOrDefault("OAuthAccessTokenSecret",
                        "8D4sZcF8trluR1dFhqxhVoaf0xsrwTvwX93qkIbKFFxKP"));
        tf = new TwitterFactory(cb.build());
    }
}

From source file:displaygrid.apps.team1100feed.Team1100TweetsServerApp.java

@Override
public void init() {

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true);//from   ww  w .j a  v a 2 s  .c o m
    cb.setOAuthConsumerKey(CONSUMER_KEY);
    cb.setOAuthConsumerSecret(CONSUMER_SECRET);
    cb.setOAuthAccessToken(ACCESS_TOKEN);
    cb.setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET);

    streamTeam = new TwitterStreamFactory(cb.build()).getInstance();
    streamTeam.addListener(this);
    streamTeam.user();

}

From source file:edu.allegheny.gatortweet.GetHomeTimeline.java

License:Apache License

public static void main(String[] args) {
    try {/*from  w w  w. ja va 2 s  . c  o  m*/
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true).setOAuthConsumerKey("rPtRCCRqdDyoxHS3E2UARA")
                .setOAuthConsumerSecret("hhDnR4NETStvN4F84km2xuBy3eXJ8l2FnjdL23YPs");
        // gets Twitter instance with default credentials
        TwitterFactory tf = new TwitterFactory(cb.build());
        Twitter twitter = tf.getInstance();
        /* Twitter twitter = new TwitterFactory().getInstance(); */
        User user = twitter.verifyCredentials();
        List<Status> statuses = twitter.getHomeTimeline();
        //System.out.println("Showing @" + user.getScreenName() + "'s home timeline.");
        for (Status status : statuses) {
            System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
        }
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get timeline: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:edu.american.student.util.TwitterSpider.java

License:Open Source License

/**
 * Grabs the last 100 tweet objects (Status) from a handle
 * @param handle/*  w w  w. jav a2s . co  m*/
 * @return
 * @throws SpiderException
 */
public static List<Status> spider(String handle) throws SpiderException {
    //connect to Twitter
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey(Constants.getTwitterOAuthConsumerKey())
            .setOAuthConsumerSecret(Constants.getTwitterOAuthConsumerSecret())
            .setOAuthAccessToken(Constants.getTwitterOAuthAccessToken())
            .setOAuthAccessTokenSecret(Constants.getTwitterOAuthAccessTokenSecret());
    TwitterFactory tf = new TwitterFactory(cb.build());

    Twitter twitter = tf.getInstance();
    //get  tweets
    Query query = new Query("from:" + handle.replace("@", ""));
    query.setCount(100);
    QueryResult result;
    try {
        result = twitter.search(query);
        List<Status> toReturn = result.getTweets();
        return toReturn;
    } catch (TwitterException e) {
        String gripe = "Twitter spider failed to...err spider!";
        throw new SpiderException(gripe, e);
    }
}

From source file:edu.csupomona.nlp.tool.crawler.Twitter.java

/**
 * Construct Twitter for crawling with Stream API
 * @throws IOException//  w w  w  .  j  a  v a  2 s  .c o  m
 */
public Twitter() throws IOException {
    // init default parameters
    lang_ = "en";
    includeRetweet_ = false;

    // init default restriction
    sizeLimit_ = 3000;
    hourLimit_ = 24; // 24 hours

    // read and construct property
    Properties key = new Properties();
    key.load(getClass().getResourceAsStream("/etc/twitter.properties"));

    // set authentication key&token
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey(key.getProperty("ConsumerKey"))
            .setOAuthConsumerSecret(key.getProperty("ConsumerSecret"))
            .setOAuthAccessToken(key.getProperty("AccessToken"))
            .setOAuthAccessTokenSecret(key.getProperty("AccessTokenSecret"));

    // create twitter stream
    ts_ = new TwitterStreamFactory(cb.build()).getInstance();

    // add listener
    ts_.addListener(new StatusListener() {

        @Override
        public void onStatus(Status status) {
            // only record tweet matches requirement
            if (isRetweetMatch(status) && !isIdRedundant(status)) {
                String text = status.getText();
                Long id = status.getId();

                text = text.replaceAll("\\n", ""); // to the same line
                tweet_.add(id.toString() + ":" + text);
                idSet_.add(id);
            }

            System.out.println(
                    "[" + idSet_.size() + "/" + sizeLimit_ + "]" + status.getId() + ": " + status.getText());

            // when limit is reached
            if (isLimitReached()) {
                try {
                    // write tweet to file
                    finishup();

                } catch (IOException ex) {
                    Logger.getLogger(Twitter.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice sdn) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public void onTrackLimitationNotice(int i) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public void onScrubGeo(long l, long l1) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public void onStallWarning(StallWarning sw) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public void onException(Exception excptn) {
            excptn.printStackTrace();

            // anything wrong, just save everything we have and stop
            try {
                finishup();

            } catch (IOException ex) {
                Logger.getLogger(Twitter.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });

}

From source file:edu.lander.twitter.TwitStreaming.java

public void prepareDownloadTweets(int newType, long limit) {
    setType(newType);//from   w w w .  j a  va  2s  .c  o  m
    if (getType() == TIME_LIMIT) {
        timeTweetDownloadLimit = limit;
    } else if (getType() == NUMBER_LIMIT) {
        nTweetDownloadLimit = limit;
    }

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey(getConsumerKey()).setOAuthConsumerSecret(getConsumerSecret())
            .setOAuthAccessToken(getAccessToken()).setOAuthAccessTokenSecret(getAccessTokenSecret())
            .setJSONStoreEnabled(true);
    connectMongoDB();
    listener = new TweetDownloadListener(this);
    twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
    twitterStream.addListener(listener);
}

From source file:edu.mum.cs.wap.TwitterUtil.java

private static Twitter getTwitter() {
    if (twitter == null) {
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true).setOAuthConsumerKey("ZhsCVnhHjs54ZLCxgE82n6GEa")
                .setOAuthConsumerSecret("FixRe4imh376SRWcxgoF14GdyaQjW7tLHE13mxcgNXNiObwSnr")
                .setOAuthAccessToken("935445715-EcVDaqqw7QQgcviXSOWWDT5ZCT8LkHbBNP1Pzd1W")
                .setOAuthAccessTokenSecret("PJIEzaRZB21tZP01CAaZEoEaVEcVvIRK6jMOlDyqc0peL");
        TwitterFactory tf = new TwitterFactory(cb.build());
        twitter = tf.getInstance();/*from www  .ja v a  2  s .  c  o  m*/
    }
    return twitter;
}

From source file:edu.smc.mediacommons.panels.TwitterPanel.java

License:Open Source License

public TwitterPanel() {
    setLayout(null);/* w  ww  . j ava2 s .  c om*/

    jButton = Utils.createButton("Login", 210, 100, 100, 20, null);
    add(jButton);

    passwordField = new JPasswordField();
    passwordField.setBounds(110, 100, 100, 20);
    add(passwordField);

    message = Utils.createLabel("Sign-in to Authenticate API calls", 80, 70, 300, 20,
            Resources.VERDANA_14_BOLD);
    add(message);

    // You can use your own credentials, and choose to encrypt them or not

    /*
    String tempEncrypted = null;
            
            
    try {
    InputStream inputStream = Main.class.getClassLoader().getResourceAsStream("YOUR_PATH");
    InputStreamReader streamReader = new InputStreamReader(inputStream, "UTF-8");
    BufferedReader reader = new BufferedReader(streamReader);
    tempEncrypted = reader.readLine();
    } catch (IOException e) {
            
    }*/

    final String encrypted = null;

    jButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
                textEncryptor.setPassword(passwordField.getText());
                String[] decrypted = textEncryptor.decrypt(encrypted).split("\\$");

                ConfigurationBuilder cb = new ConfigurationBuilder();
                cb.setDebugEnabled(true).setOAuthConsumerKey(decrypted[0]).setOAuthConsumerSecret(decrypted[1])
                        .setOAuthAccessToken(decrypted[2]).setOAuthAccessTokenSecret(decrypted[3]);

                TwitterFactory tf = new TwitterFactory(cb.build());
                twitterModule = new TwitterModule(tf.getInstance());
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(getParent(), "The input password was not correct.");
                return;
            }

            JOptionPane.showMessageDialog(getParent(), "Authentication successful.");
            restructurePanel();
        }
    });
}

From source file:edu.uci.ics.asterix.external.util.TwitterUtil.java

License:Apache License

private static ConfigurationBuilder getAuthConfiguration(Map<String, String> configuration) {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true);// ww  w  .  ja v  a2s.c o  m
    String oAuthConsumerKey = configuration.get(AuthenticationConstants.OAUTH_CONSUMER_KEY);
    String oAuthConsumerSecret = configuration.get(AuthenticationConstants.OAUTH_CONSUMER_SECRET);
    String oAuthAccessToken = configuration.get(AuthenticationConstants.OAUTH_ACCESS_TOKEN);
    String oAuthAccessTokenSecret = configuration.get(AuthenticationConstants.OAUTH_ACCESS_TOKEN_SECRET);

    cb.setOAuthConsumerKey(oAuthConsumerKey);
    cb.setOAuthConsumerSecret(oAuthConsumerSecret);
    cb.setOAuthAccessToken(oAuthAccessToken);
    cb.setOAuthAccessTokenSecret(oAuthAccessTokenSecret);
    return cb;
}

From source file:ens.demo.twitter.TwittEmergencyMessage.java

@Override
public void run() {
    try {/*from  w  w w.  j  ava  2  s  .c  om*/
        if (toCustomer.getToken() == null || toCustomer.getToken().isEmpty()) {
            return;
        }
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        Properties properties = new Properties();
        properties.load(classLoader.getResourceAsStream("twitter4j.properties"));
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true).setOAuthConsumerKey(properties.getProperty("twitter4j.oauth.consumerKey"))
                .setOAuthConsumerSecret(properties.getProperty("twitter4j.oauth.consumerSecret"))
                .setOAuthAccessToken(toCustomer.getToken())
                .setOAuthAccessTokenSecret(toCustomer.getTokenSecret());
        TwitterFactory tf = new TwitterFactory(cb.build());
        Twitter twitter = tf.getInstance();
        StatusUpdate update = new StatusUpdate(message);
        Status status = twitter.updateStatus(update);
        System.out.println("Successfully updated the status to [" + status.getText() + "].");
    } catch (TwitterException ex) {
        Logger.getLogger(TwittEmergencyMessage.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(TwittEmergencyMessage.class.getName()).log(Level.SEVERE, null, ex);
    }
}