Search code examples
twittertwitter4j

Twitter4j: Get all members of a list


How do I get all the members of a list ?

I tried the following function.

int cursor=-1;
twitter.getUserListMembers(LIST_ID, cursor);

But it returns only 20 members. If I decrement or increment the value of cursor, the results are same. The list contains more than 100 users.


Solution

  •             Set<String> members=new HashSet<String>();
                long cursor = -1;
                PagableResponseList<User> membes;
                do {
                    membes = twitter.getUserListMembers(LIST_ID,cursor);
                    for (User mem : membes) {
                        members.add(mem.getScreenName());
                    }
                } while ((cursor = membes.getNextCursor()) != 0);