简体   繁体   中英

Getting friends picture using facebook-android-SDK

I'm getting friends ids and names using

mAsyncRunner.request("me/friends", new FriendRequestListener());

but I also need the friends profile pictures. I could loop over the friends to get them, but this is many requests.

Is there any way to get friends ids, names AND pictures in one request?

Thanks

Unfortunately not because friends list is a JSON encoded answer and including all pic would be a huge response.
You have to call http://graph.facebook.com/ + userid + /picture?type=large (omit ?type=large if you want small sized version) for every friend.

You wrote:

Is there any way to get friends ids, names AND pictures in one request?

Yes, it's possible, using FQL and the User and Friend FQL tables:

SELECT uid, name, pic, pic_small, pic_big, FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())

In your Android app you can make the FQL query like so:

String query = "SELECT uid, name, pic, pic_small, pic_big FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())";

Bundle params = new Bundle();
params.putString("method", "fql.query");
params.putString("query", query);
mAsyncFacebookRunner.request(null, params, new CustomRequestListener());

where CustomRequestListener() extends RequestListener in the Facebook Android SDK.

This will return:

  • id
  • user name
  • URLs for default, small and big profile images

for the current user's friends.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM