Example usage for twitter4j TwitterException getMessage

List of usage examples for twitter4j TwitterException getMessage

Introduction

In this page you can find the example usage for twitter4j TwitterException getMessage.

Prototype

@Override
    public String getMessage() 

Source Link

Usage

From source file:twitter4j.examples.suggestedusers.GetUserSuggestions.java

License:Apache License

/**
 * Usage: java twitter4j.examples.suggestedusers.GetUserSuggestions [slug]
 *
 * @param args message//from w ww .  j  a va  2s.  co  m
 */
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("Usage: java twitter4j.examples.suggestedusers.GetUserSuggestions [slug]");
        System.exit(-1);
    }
    System.out.println("Showing suggested users in " + args[0] + " category.");
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        ResponseList<User> users = twitter.getUserSuggestions(args[0]);
        for (User user : users) {
            if (user.getStatus() != null) {
                System.out.println("@" + user.getScreenName() + " - " + user.getStatus().getText());
            } else {
                // the user is protected
                System.out.println("@" + user.getScreenName());
            }
        }
        System.out.println("done.");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get suggested users: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:twitter4j.examples.timeline.GetUserTimeline.java

License:Apache License

/**
 * Usage: java twitter4j.examples.timeline.GetUserTimeline
 *
 * @param args String[]/*from  w w w.j  a  v a 2 s .c  om*/
 */
public static void main(String[] args) {
    // gets Twitter instance with default credentials
    Twitter twitter = new TwitterFactory().getInstance();
    try {
        List<Status> statuses;
        String user;
        if (args.length == 1) {
            user = args[0];
            statuses = twitter.getUserTimeline(user);
        } else {
            user = twitter.verifyCredentials().getScreenName();
            statuses = twitter.getUserTimeline();
        }
        System.out.println("Showing @" + user + "'s user 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:twitter4j.examples.trends.GetAvailableTrends.java

License:Apache License

/**
 * Usage: java twitter4j.examples.trends.GetAvailableTrends
 *
 * @param args message//www  .j  a va 2  s.c  o  m
 */
public static void main(String[] args) {
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        ResponseList<Location> locations;
        locations = twitter.getAvailableTrends();
        System.out.println("Showing available trends");
        for (Location location : locations) {
            System.out.println(location.getName() + " (woeid:" + location.getWoeid() + ")");
        }
        System.out.println("done.");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get trends: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:twitter4j.examples.trends.GetPlaceTrends.java

/**
 * Usage: java twitter4j.examples.trends.GetPlaceTrends [WOEID=0]
 *
 * @param args message//from   w  ww .jav a2 s.c o m
 */
public static void main(String[] args) {
    try {
        int woeid = args.length > 0 ? Integer.parseInt(args[0]) : 1;
        Twitter twitter = new TwitterFactory().getInstance();
        Trends trends = twitter.getPlaceTrends(woeid);

        System.out.println("Showing trends for " + trends.getLocation().getName());

        for (Trend trend : trends.getTrends()) {
            System.out.println(String.format("%s (tweet_volume: %d)", trend.getName(), trend.getTweetVolume()));
        }

        System.out.println("done.");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get trends: " + te.getMessage());
        System.exit(-1);
    } catch (NumberFormatException nfe) {
        nfe.printStackTrace();
        System.out.println("WOEID must be number");
        System.exit(-1);
    }
}

From source file:twitter4j.examples.tweets.DestroyStatus.java

License:Apache License

/**
 * Usage: java twitter4j.examples.tweets.DestroyStatus [status id]
 *
 * @param args message/*w w w  .  ja  v  a  2s.  c  o  m*/
 */
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("Usage: java twitter4j.examples.tweets.DestroyStatus [status id]");
        System.exit(-1);
    }
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        twitter.destroyStatus(Long.parseLong(args[0]));
        System.out.println("Successfully deleted status [" + args[0] + "].");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to delete status: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:twitter4j.examples.tweets.GetRetweets.java

License:Apache License

/**
 * Usage: java twitter4j.examples.tweets.GetRetweets [status id]
 *
 * @param args message/*from w w  w.  j av  a2s  . c  o m*/
 */
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("Usage: java twitter4j.examples.tweets.GetRetweets [status id]");
        System.exit(-1);
    }
    System.out.println("Showing up to 100 of the first retweets of the status id - [" + args[0] + "].");
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        List<Status> statuses = twitter.getRetweets(Long.parseLong(args[0]));
        for (Status status : statuses) {
            System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
        }
        System.out.println("done.");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get retweets: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:twitter4j.examples.tweets.RetweetStatus.java

License:Apache License

/**
 * Usage: java twitter4j.examples.tweets.RetweetStatus [status id]
 *
 * @param args message//from w  w w .j av  a 2s  . com
 */
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("Usage: java twitter4j.examples.tweets.RetweetStatus [status id]");
        System.exit(-1);
    }
    System.out.println("Retweeting the status id - [" + args[0] + "].");
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        twitter.retweetStatus(Long.parseLong(args[0]));
        System.out.println("Successfully retweeted status [" + args[0] + "].");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to retweet: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:twitter4j.examples.tweets.ShowStatus.java

License:Apache License

/**
 * Usage: java twitter4j.examples.tweets.ShowStatus [status id]
 *
 * @param args message/*from w  w  w  .  jav  a  2s. co m*/
 */
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("Usage: java twitter4j.examples.tweets.ShowStatus [status id]");
        System.exit(-1);
    }
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        Status status = twitter.showStatus(Long.parseLong(args[0]));
        System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to show status: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:twitter4j.examples.tweets.UploadMultipleImages.java

License:Apache License

/**
 * Usage: java twitter4j.examples.tweets.UploadMultipleImages [text] [file1] [file2] ...
 *
 * @param args message/*from  w w w . ja v a 2s  . c o  m*/
 */
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println(
                "Usage: java twitter4j.examples.tweets.UploadMultipleImages [text] [file1] [file2] ...");
        System.exit(-1);
    }
    try {
        Twitter twitter = new TwitterFactory().getInstance();

        long[] mediaIds = new long[args.length - 1];
        for (int i = 1; i < args.length; i++) {
            System.out.println("Uploading...[" + i + "/" + (args.length - 1) + "][" + args[i] + "]");
            UploadedMedia media = twitter.uploadMedia(new File(args[i]));
            System.out.println("Uploaded: id=" + media.getMediaId() + ", w=" + media.getImageWidth() + ", h="
                    + media.getImageHeight() + ", type=" + media.getImageType() + ", size=" + media.getSize());
            mediaIds[i - 1] = media.getMediaId();
        }

        StatusUpdate update = new StatusUpdate(args[0]);
        update.setMediaIds(mediaIds);
        Status status = twitter.updateStatus(update);
        System.out.println(
                "Successfully updated the status to [" + status.getText() + "][" + status.getId() + "].");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to update status: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:twitter4j.examples.user.LookupUsers.java

License:Apache License

/**
 * Usage: java twitter4j.examples.user.LookupUsers [screen name[,screen name..]]
 *
 * @param args message//  w  w  w .  j  a v  a 2s. c  om
 */
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("Usage: java twitter4j.examples.user.LookupUsers [screen name[,screen name..]]");
        System.exit(-1);
    }
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        ResponseList<User> users = twitter.lookupUsers(args[0].split(","));
        for (User user : users) {
            if (user.getStatus() != null) {
                System.out.println("@" + user.getScreenName() + " - " + user.getStatus().getText());
            } else {
                // the user is protected
                System.out.println("@" + user.getScreenName());
            }
        }
        System.out.println("Successfully looked up users [" + args[0] + "].");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to lookup users: " + te.getMessage());
        System.exit(-1);
    }
}