Get followers of a user using Twitter android sdk

android

#1

I have searched all the functions given under the com.twitter.sdk.android.core and I could not find a single one which can fetch the followers for a user. There are functions to get StatusesService, FavoritesService, AccountService but none of them have any function related to followers. Yes I know one can always Twitter’s rest api to do that but it would be great of some one could point any way of doing this using twitter’s android sdk.
And in case there isn’t any way then please mention it so that I could shift my focus on REST apis.


#2

You can extend the TwitterApiClient per the example in the documentation. If you hit /1.1/followers/list you’ll be on your way.


#3

I tried as per your suggestions but in the response I am getting all the parameters with null value. Following is the extended TwitterApiCllient I am using:

public class MyTwitterApiClient extends TwitterApiClient {
public MyTwitterApiClient(TwitterSession session) {
    super(session);
}

public CustomService getCustomService() {
    return getService(CustomService.class);
}

}

interface CustomService {
@GET("/1.1/followers/list.json")
void show(@Query("screen_name")  String var, @Query("skip_status") Boolean var1, @Query("include_user_entities") Boolean var2, @Query("count") Integer var3, Callback<User> cb);

}

Another doubt I have is that the result is supposed to be an array but the response I am getting is an object and that is why I have only used User and not List of User as argument in Callback. On using List in Callback I get the following exception:

com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2

Because of this exception I am using only User in Callback.
What might be the reason behind null values in the response ? Am I doing anything wrong ?

Code snippet of how I am calling the function

customService.show("pranjalsahu", true, false, 10, new Callback<User>() {

        @Override
        public void success(Result<User> result) {

            User user = result.data;
            System.out.println("test "+user.createdAt);
            System.out.println("test "+user.toString());
            System.out.println("test "+user.idStr);
            System.out.println("test "+user.id);
            System.out.println("test "+user.name);
            System.out.println("test "+user.friendsCount);
            System.out.println("test "+user.location);
            System.out.println("test "+user.screenName);
            System.out.println("test "+user.verified);
            System.out.println("test "+user.statusesCount);
        }

        @Override
        public void failure(TwitterException e) {
            e.printStackTrace();
        }
    });

#4

I am having the same issue. What’s to be done?


#5

I have implemented twitter login using TwitterCore https://docs.fabric.io/android/twitter/authentication.html ; and when I am calling https://api.twitter.com/1.1/followers/list.json?cursor=-1&screen_name=twitterdev&skip_status=true&include_user_entities=false to get list of followers but in response I am getting:

{
    "errors": [
        {
            "code": 215,
            "message": "Bad Authentication data."
        }
    ]
}

So how can I fix this?


#6