Example usage for twitter4j Twitter searchUsers

List of usage examples for twitter4j Twitter searchUsers

Introduction

In this page you can find the example usage for twitter4j Twitter searchUsers.

Prototype

ResponseList<User> searchUsers(String query, int page) throws TwitterException;

Source Link

Document

Run a search for users similar to the Find People button on Twitter.com; the same results returned by people search on Twitter.com will be returned by using this API.
Usage note: It is only possible to retrieve the first 1000 matches from this API.

Usage

From source file:User.SearchUsers.java

License:Apache License

public String[] getResults(String name) {
    try {//  w  w w. j a  v a 2s.c  o  m
        Twitter twitter = builder.twitter;
        int page = 1;
        int i = 0;
        ResponseList<User> users;
        String[] persons = new String[100];
        do {
            users = twitter.searchUsers(name, page);
            for (User user : users) {
                String str = "";
                if (user != null) {
                    if (user.getName() != null && !user.getName().equals("null")
                            && !user.getName().equals("")) {
                        str = str + user.getName() + ";";
                        System.out.println(user.getName());
                        if (user.getLocation() != null) {
                            str = str + user.getLocation() + ";";
                        } else {
                            str = str + "N/A;";
                        }

                        if (user.getMiniProfileImageURL() != null) {
                            str = str + user.getProfileImageURL();
                        } else {
                            str = str + "N/A";
                        }

                        persons[i] = str;
                        i++;
                    }
                }
            }
            page++;
        } while (users.size() != 0 && page < 2);
        return persons;
    } catch (TwitterException te) {
        te.printStackTrace();
    }
    return null;
}