Search code examples
javatwitter4jnomethoderror

Method ListsResources.getUserListMemberships not recognized in Twitter4J 4.0.4


when calling

twitter.list().getUserListMemberships(userId, 1000,1,false);

I get this error:

java.lang.NoSuchMethodError: twitter4j.api.ListsResources.getUserListMemberships(JIJ)Ltwitter4j/PagableResponseList;

I read the javadoc for this method (see here), and I don't see what I am doing wrong? And I did verify that my dependencies are OK. Any clue?


Solution

  • I just use Twitter4j 4.0.2 and that method doesn't exist 4.0.2

    But on Twitter4j 4.0.4 does exist 4.0.4

    So, Are you sure that you are using 4.0.4?
    Keep in mind too that you are using cursor 1 on the first call but you have to use -1. I just run this code and works

        User user = twitter.showUser("lt_deportes");
           long cursor = -1;
            PagableResponseList<UserList> lists;
                    do {
                lists =  twitter.list().getUserListMemberships(user.getId(),1000,cursor,false);
                for (UserList list : lists) {
                    System.out.println("id:" + list.getId() + ", name:" + list.getName() + ", description:"
                            + list.getDescription() + ", slug:" + list.getSlug() + "");
                }
            } while ((cursor = lists.getNextCursor()) != 0);