Example usage for twitter4j User getScreenName

List of usage examples for twitter4j User getScreenName

Introduction

In this page you can find the example usage for twitter4j User getScreenName.

Prototype

String getScreenName();

Source Link

Document

Returns the screen name of the user

Usage

From source file:twitter4j.examples.account.VerifyCredentials.java

License:Apache License

/**
 * Usage: java twitter4j.examples.account.VerifyCredentials
 *
 * @param args message//from www  .j ava2 s . c  om
 */
public static void main(String[] args) {
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        User user = twitter.verifyCredentials();
        System.out.println("Successfully verified credentials of " + user.getScreenName());
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to verify credentials: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:twitter4j.examples.block.GetBlockingUsers.java

License:Apache License

/**
 * Usage: java twitter4j.examples.block.GetBlockingUsers
 *
 * @param args message// w w w  . ja v a  2 s .c om
 */
public static void main(String[] args) {
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        int page = 1;
        List<User> users;
        do {
            users = twitter.getBlocksList(page);
            for (User user : users) {
                System.out.println("@" + user.getScreenName());
            }
            page++;
            // this code ends up in an infinite loop due to the issue 1988
            // http://code.google.com/p/twitter-api/issues/detail?id=1988
        } while (users.size() > 0 && page <= 10);
        System.out.println("done.");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get blocking users: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:twitter4j.examples.list.GetUserListMembers.java

License:Apache License

/**
 * Usage: java twitter4j.examples.list.GetUserListMembers [list owner screen name] [list id]
 *
 * @param args message/*  w ww.  ja v  a 2s. c  om*/
 */
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("Usage: java twitter4j.examples.list.GetUserListMembers [list id]");
        System.exit(-1);
    }
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        long cursor = -1;
        PagableResponseList<User> usres;
        do {
            usres = twitter.getUserListMembers(Integer.parseInt(args[0]), cursor);
            for (User list : usres) {
                System.out.println("@" + list.getScreenName());
            }
        } while ((cursor = usres.getNextCursor()) != 0);
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get list members: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:twitter4j.examples.list.GetUserListSubscribers.java

License:Apache License

/**
 * Usage: java twitter4j.examples.list.GetUserListSubscribers [list id]
 *
 * @param args message/*from   w w w.j a  v  a  2  s.com*/
 */
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("Usage: java twitter4j.examples.list.GetUserListSubscribers [list id]");
        System.exit(-1);
    }
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        long cursor = -1;
        PagableResponseList<User> usres;
        do {
            usres = twitter.getUserListSubscribers(Integer.parseInt(args[0]), cursor);
            for (User list : usres) {
                System.out.println("@" + list.getScreenName());
            }
        } while ((cursor = usres.getNextCursor()) != 0);
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get list subscribers: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:twitter4j.examples.list.ShowUserListMembership.java

License:Apache License

/**
 * Usage: java twitter4j.examples.list.ShowUserListMembership [list id] [user id]
 *
 * @param args message// w w  w . ja v a 2 s . c om
 */
public static void main(String[] args) {
    if (args.length < 2) {
        System.out.println("Usage: java twitter4j.examples.list.ShowUserListMembership [list id] [user id]");
        System.exit(-1);
    }
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        long listId = Long.parseLong(args[0]);
        UserList list = twitter.showUserList(listId);
        long userId = Integer.parseInt(args[1]);
        User user = twitter.showUser(userId);
        try {
            twitter.showUserListMembership(listId, userId);
            System.out.println("@" + user.getScreenName() + " is in the list:" + list.getName());
        } catch (TwitterException te) {
            if (te.getStatusCode() == 404) {
                System.out.println("@" + user.getScreenName() + " is not in the list:" + list.getName());
            }
        }
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to check user membership: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:twitter4j.examples.list.ShowUserListSubscription.java

License:Apache License

/**
 * Usage: java twitter4j.examples.list.ShowUserListSubscription [list id] [user id]
 *
 * @param args message/*from w ww  . j av  a 2 s.  co  m*/
 */
public static void main(String[] args) {
    if (args.length < 2) {
        System.out.println("Usage: java twitter4j.examples.list.ShowUserListSubscription [list id] [user id]");
        System.exit(-1);
    }
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        long listId = Long.parseLong(args[0]);
        UserList list = twitter.showUserList(listId);
        long userId = Integer.parseInt(args[1]);
        User user = twitter.showUser(userId);
        try {
            twitter.showUserListSubscription(listId, userId);
            System.out.println("@" + user.getScreenName() + " is subscribing the list:" + list.getName());
        } catch (TwitterException te) {
            if (te.getStatusCode() == 404) {
                System.out.println(
                        "@" + user.getScreenName() + " is not subscribing  the list:" + list.getName());
            }
        }
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to check user subscription: " + te.getMessage());
        System.exit(-1);
    }
}

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

License:Apache License

/**
 * Usage: java twitter4j.examples.suggestedusers.GetMemberSuggestions [slug]
 *
 * @param args message/* ww w  .j  a v  a  2s. c o  m*/
 */
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("Usage: java twitter4j.examples.suggestedusers.GetMemberSuggestions [slug]");
        System.exit(-1);
    }
    System.out.println("Showing suggested users in " + args[0] + " category.");
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        ResponseList<User> users = twitter.getMemberSuggestions(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.suggestedusers.GetUserSuggestions.java

License:Apache License

/**
 * Usage: java twitter4j.examples.suggestedusers.GetUserSuggestions [slug]
 *
 * @param args message/* w  ww  . ja  va 2s  .  c  o 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.user.LookupUsers.java

License:Apache License

/**
 * Usage: java twitter4j.examples.user.LookupUsers [screen name[,screen name..]]
 *
 * @param args message//from  ww w .  j  a  va2  s .c  o  m
 */
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);
    }
}

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

License:Apache License

/**
 * Usage: java twitter4j.examples.user.SearchUsers [query]
 *
 * @param args message//www . ja v a 2s . c om
 */
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("Usage: java twitter4j.examples.user.SearchUsers [query]");
        System.exit(-1);
    }
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        int page = 1;
        ResponseList<User> users;
        do {
            users = twitter.searchUsers(args[0], page);
            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());
                }
            }
            page++;
        } while (users.size() != 0 && page < 50);
        System.out.println("done.");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to search users: " + te.getMessage());
        System.exit(-1);
    }
}