Getting friends picture using facebook-android-SDK
开发者_StackOverflowI'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.
精彩评论