din_oops
din_oops

Reputation: 708

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.

Upvotes: 1

Views: 175

Answers (1)

din_oops
din_oops

Reputation: 708

            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);

Upvotes: 2

Related Questions