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:twitterplugin.TwitterSender.java

License:Open Source License

public void send(final Window parentWindow, final Program program, final TwitterSettings settings) {
    TwitterDialog dialog = new TwitterDialog(parentWindow, program, settings.getFormat());
    dialog.setLocationRelativeTo(parentWindow);
    dialog.setVisible(true);/*from   w w w  . j a  v  a  2s.co m*/

    if (dialog.wasOkPressed()) {

        if (settings.getAccessToken() == null) {
            final TwitterLoginDialog login = new TwitterLoginDialog(parentWindow, settings);

            if (!(login.askLogin() == JOptionPane.OK_OPTION)) {
                return;
            }
        }

        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true).setOAuthConsumerKey(settings.getConsumerKey())
                .setOAuthConsumerSecret(settings.getConsumerSecret());
        TwitterFactory factory = new TwitterFactory(cb.build());
        AccessToken accessToken = settings.getAccessToken();
        Twitter twitter = factory.getInstance(accessToken);
        try {
            twitter.updateStatus(dialog.getMessage());
            DontShowAgainMessageBox.dontShowAgainMessageBox(TwitterPlugin.getInstance(), "tweetSent",
                    parentWindow, mLocalizer.msg("tweetSend", "The tweet was sent."));
        } catch (TwitterException e) {
            e.printStackTrace();
            ErrorHandler.handle(mLocalizer.msg("error", "Could not send tweet..."), e);
        }
    }
}

From source file:twitterrest.Followersids.java

License:Apache License

public static void main(String[] args) throws TwitterException {

    String ScreenName = "anondroid5";//??

    // ?//w w w .  ja v  a 2 s . c o  m
    Configuration configuration = new ConfigurationBuilder().setOAuthConsumerKey(CONSUMER_KEY)
            .setOAuthConsumerSecret(CONSUMER_SECRET).setOAuthAccessToken(ACCESS_TOKEN)
            .setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET).build();
    Twitter twitter = new TwitterFactory(configuration).getInstance();

    List<Long> followersList = followers(twitter, ScreenName);//?
    System.out.println(ScreenName + ":FolloweID List");
    for (int i = 0; i < followersList.size(); i++) {
        System.out.println("[" + (i + 1) + "]" + followersList.get(i));
        //?
        User user = twitter.showUser(followersList.get(i));
        System.out.println("User ID : " + user.getId());//UserID
        System.out.println("ScreenName : " + user.getScreenName());//ScreenName
        System.out.println("User's Name : " + user.getName());//UserName
        System.out.println("Number of Followers : " + user.getFollowersCount());//Number of Followers
        System.out.println("Number of Friends : " + user.getFriendsCount());//Number of Friends
        System.out.println("Language : " + user.getLang());//Language
    }
}

From source file:twitterrest.GeoSearch.java

License:Apache License

public static void main(String[] args) throws TwitterException {
    // ?// www  .  j  ava2s  .  c o  m
    Configuration configuration = new ConfigurationBuilder().setOAuthConsumerKey(CONSUMER_KEY)
            .setOAuthConsumerSecret(CONSUMER_SECRET).setOAuthAccessToken(ACCESS_TOKEN)
            .setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET).build();
    Twitter twitter = new TwitterFactory(configuration).getInstance();
    Query query = new Query();

    // ?????10kmIP??????      
    GeoLocation geo = new GeoLocation(35.69384, 139.703549);
    query.setGeoCode(geo, 10.0, Query.KILOMETERS);

    // 
    QueryResult result = twitter.search(query);

    // ???Tweet??placegeoLocation??????
    for (Status tweet : result.getTweets()) {
        System.out.println(tweet.getText());
        System.out.println(tweet.getPlace() + " : " + tweet.getGeoLocation());
    }
}

From source file:twitterrest.GetHomeTimeline.java

License:Apache License

public static void main(String[] args) {
    try {/*www  .  j a v  a  2  s  . c  o m*/
        // ?
        Configuration configuration = new ConfigurationBuilder().setOAuthConsumerKey(CONSUMER_KEY)
                .setOAuthConsumerSecret(CONSUMER_SECRET).setOAuthAccessToken(ACCESS_TOKEN)
                .setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET).build();
        Twitter twitter = new TwitterFactory(configuration).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:twitterrest.SearchTweet.java

License:Apache License

public static void main(String[] args) throws TwitterException {
    //?//from   w  w  w . j a v  a  2 s  .com
    Configuration configuration = new ConfigurationBuilder().setOAuthConsumerKey(CONSUMER_KEY)
            .setOAuthConsumerSecret(CONSUMER_SECRET).setOAuthAccessToken(ACCESS_TOKEN)
            .setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET).build();
    Twitter twitter = new TwitterFactory(configuration).getInstance();
    Query query = new Query();
    try {
        File file = new File("./file/tweets.txt");
        PrintWriter pw;
        //???
        pw = new PrintWriter(new BufferedWriter(new FileWriter(file, true)));

        // ???
        query.setQuery("?");
        query.setLang("ja");
        // 1????Tweet?100?
        query.setCount(100);
        //?????????
        //query.setSince("2013-06-13");
        //query.setUntil("2013-06-17");

        // 150015
        for (int i = 1; i <= 15; i++) {
            // 
            QueryResult result = twitter.search(query);
            System.out.println(": " + result.getTweets().size());
            System.out.println(" : " + new Integer(i).toString());

            // ???
            for (Status tweet : result.getTweets()) {
                // 
                String str = tweet.getText();
                System.out.println(str);
                //
                System.out.println(tweet.getUser());
                //
                System.out.println(tweet.getCreatedAt());
                // ??URL?   
                StringTokenizer sta = new StringTokenizer(str, " ");
                //?
                while (sta.hasMoreTokens()) {
                    String wk = sta.nextToken();
                    if (wk.indexOf("#") == -1 && wk.indexOf("http") == -1 && wk.indexOf("RT") == -1
                            && wk.indexOf("@") == -1) {
                        pw.println(wk);
                    }
                }
                String u = tweet.getUser().getName();
                pw.println(u);
            }
            if (result.hasNext()) {
                query = result.nextQuery();
            } else {
                break;
            }
        }
        pw.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:twitterrest.Timeline.java

License:Apache License

public static void main(String[] args) throws TwitterException {

    Configuration configuration = new ConfigurationBuilder().setOAuthConsumerKey(CONSUMER_KEY)
            .setOAuthConsumerSecret(CONSUMER_SECRET).setOAuthAccessToken(ACCESS_TOKEN)
            .setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET).build();

    Twitter tw = new TwitterFactory(configuration).getInstance();
    List<Status> list = tw.getUserTimeline("masason");//ScreenName[anondroid5]

    for (Status status : list) {
        System.out.print(status.getCreatedAt() + " ");//CreatedDate
        System.out.print(status.getUser().getScreenName() + " ");//ScreenName
        System.out.println(status.getText());//tweet
    }/*from   w  w  w  .ja v  a2 s  .  com*/
}

From source file:twitterrest.Tweet.java

License:Apache License

public static void main(String[] args) throws IOException, TwitterException {
    //?/* w  ww  .j a  va  2 s. c  o  m*/
    Configuration configuration = new ConfigurationBuilder().setOAuthConsumerKey(CONSUMER_KEY)
            .setOAuthConsumerSecret(CONSUMER_SECRET).setOAuthAccessToken(ACCESS_TOKEN)
            .setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET).build();
    Twitter tw = new TwitterFactory(configuration).getInstance();
    //date?
    Date date = new Date();
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd (EE) HH:mm:ss");

    //tweet Input
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String tweet = "";
    while (tweet.isEmpty()) {
        System.out.print("?? ? : ");
        tweet = br.readLine();
        if (tweet.length() > 140) {
            System.out.println("??????");
            tweet = "";
            continue;
        }
    }
    Status status = tw.updateStatus(tweet + df.format(date));//tweet
    System.out.println(status.getUser().getScreenName() + " ??????? : " + status.getText());
    br.close();
}

From source file:twitterrest.UserSearch.java

License:Apache License

public static void main(String[] args) throws TwitterException {
    //?//from ww  w .j  a v a2  s  .  c  o m
    Configuration configuration = new ConfigurationBuilder().setOAuthConsumerKey(CONSUMER_KEY)
            .setOAuthConsumerSecret(CONSUMER_SECRET).setOAuthAccessToken(ACCESS_TOKEN)
            .setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET).build();
    Twitter twitter = new TwitterFactory(configuration).getInstance();
    Query query = new Query();

    // masason?Tweet
    //query.setQuery("from:anondroid3 OR to:anondroid3");
    query.setQuery("from:anondroid3");

    // ???
    QueryResult result = twitter.search(query);
    //
    System.out.println(":" + result.getTweets().size());
    // 1????Tweet?100?
    query.setCount(100);

    for (Status tweet : result.getTweets()) {
        System.out.println("tweet:" + tweet.getText());//
        System.out.println("UserID:" + tweet.getUser().getId());//ID
        System.out.println("Application:" + tweet.getSource());//
        System.out.println("Created Date:" + tweet.getCreatedAt());//?
        System.out.println("GeoLocation:" + tweet.getGeoLocation());//
    }
}

From source file:twittersentimentanalysis.TwitterSentimentAnalysis.java

private static ConfigurationBuilder getAuthentication() {
    logger.info("getAuthentication()");
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setOAuthConsumerKey("******************");
    cb.setOAuthConsumerSecret("******************");
    cb.setOAuthAccessToken("******************");
    cb.setOAuthAccessTokenSecret("******************");
    return cb;/*from  w w  w  .j av a 2s  . c  o m*/
}

From source file:TwitterStats.Facade.Twitter.java

public Twitter() {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey("4bUGil5YTghhAZj05wJZX0wjB");
    builder.setOAuthAccessToken("330584281-bFRvETvWXnH7fb9acRMIIagP1oGQeMK0mv4RiIUB");
    builder.setOAuthConsumerSecret("nZPD0wtVuQRmqSdyEnGN4d8TRv63BPlUvkVOAZSZ2O8DfDGwGX");
    builder.setOAuthAccessTokenSecret("FGSC23QvIqBYRKleno9OQI3eBo8J54hZ5btpAf1jR2bYy");
    twitter4j.conf.Configuration configuration = builder.build();
    twitter = (new TwitterFactory(configuration)).getInstance();
}