Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get friend list of twitter using Social Auth in android?

I am using Social Auth Api for twitter integration. It is working fine, but I am not getting any method to get friend list (By friend list i mean list of friends following me) from twitter. Is this possible to get this from Social Auth or do I need to implement twitter SDK?

like image 545
Meenal Avatar asked Jan 04 '14 10:01

Meenal


1 Answers

I can't found a way to do this with the SocialAuth API but I found two other ways with another API or a manual call of the official Twitter API. You can use the jTwitter API for Android with this code:

List<User> followers= twitter.getFollowers();
for(int i=0;i<followers.size();i++)
{
     User follower=followers.get(i);
     String name=follower.getName();
     Log.i("follower", name);
}

List<User> following = twitter.getFriends();
for(int i=0;i<following.size();i++)
{
     User user=following.get(i);
     String name=user.getName();
     Log.i("following", name);
}

Or a second way to do this is, that you can use the official Twitter API. For this you need the Screen name from the user and then pass it to an URL and the response is an array of UserIds:

HttpParameters params1 = mProvider.getResponseParameters();
String ScreeName = params1.getFirst("screen_name");

https://api.twitter.com/1/friends/ids.json?cursor=-1&screen_name="+ScreeName

Of course you have to call this in an own Thread or AsyncTask. I think the first version is much more easier, because you don't have to think about Thread syncronisation and so on but the second does not require so much space on the phone. It's your decision what is more important for you.

like image 186
Cilenco Avatar answered Nov 14 '22 23:11

Cilenco