简体   繁体   English

使用facebook-android-SDK获取朋友图片

[英]Getting friends picture using facebook-android-SDK

I'm getting friends ids and names using 我正在使用朋友ID和名字

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? 有没有办法在一个请求中获取朋友ID,姓名和图片?

Thanks 谢谢

Unfortunately not because friends list is a JSON encoded answer and including all pic would be a huge response. 不幸的是,不是因为朋友列表是一个JSON编码的答案,包括所有pic将是一个巨大的回应。
You have to call http://graph.facebook.com/ + userid + /picture?type=large (omit ?type=large if you want small sized version) for every friend. 你必须为每个朋友打电话http://graph.facebook.com/ + userid + /picture?type=large (如果你想要小尺寸版本,省略?type=large )。

You wrote: 你写了:

Is there any way to get friends ids, names AND pictures in one request? 有没有办法在一个请求中获取朋友ID,姓名和图片?

Yes, it's possible, using FQL and the User and Friend FQL tables: 是的,可以使用FQL以及UserFriend FQL表:

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: 在您的Android应用中,您可以像这样进行FQL查询:

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. 其中CustomRequestListener()在Facebook Android SDK中扩展RequestListener

This will return: 这将返回:

  • id ID
  • user name 用户名
  • URLs for default, small and big profile images 默认,小型和大型个人资料图片的网址

for the current user's friends. 为当前用户的朋友。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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