Search code examples
androidtwittertwitter4j

How to get list of all twitter followers using twitter4j?


I have been wondering if there is a way to access all the twitter followers list.

We have tried using call to the REST API via twitter4j:

  public List<User> getFriendList() {
    List<User> friendList = null;
    try {
        friendList = mTwitter.getFollowersList(mTwitter.getId(), -1);

    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (TwitterException e) {
        e.printStackTrace();
    }
    return friendList;
}

But it returns only a list of 20 followers.

I tried using the same call in loop, but it cause a rate limit exception - says we are not allowed to make too many requests in a small interval of time.

Do we have a way around this?


Solution

  • Just Change like this and try, this is working for me

        try {
            Log.i("act twitter...........", "ModifiedCustomTabBarActivity.class");
            // final JSONArray twitterFriendsIDsJsonArray = new JSONArray();
            IDs ids = mTwitter.mTwitter.getFriendsIDs(-1);// ids
            // for (long id : ids.getIDs()) {
            do {
                for (long id : ids.getIDs()) {               
    
    
                    String ID = "followers ID #" + id;
                    String[] firstname = ID.split("#");
                    String first_Name = firstname[0];
                    String Id = firstname[1];
    
                    Log.i("split...........", first_Name + Id);
    
                    String Name = mTwitter.mTwitter.showUser(id).getName();
                    String screenname = mTwitter.mTwitter.showUser(id).getScreenName();
    
    
      //            Log.i("id.......", "followers ID #" + id);
        //          Log.i("Name..", mTwitter.mTwitter.showUser(id).getName());
        //          Log.i("Screen_Name...", mTwitter.mTwitter.showUser(id).getScreenName());
        //          Log.i("image...", mTwitter.mTwitter.showUser(id).getProfileImageURL());
    
    
                }
            } while (ids.hasNext());
    
        } catch (Exception e) {
            e.printStackTrace();
        }