以最快的方式获取Facebook好友个人资料图片 - iOS

时间:2013-04-26 15:47:33

标签: iphone ios objective-c facebook facebook-graph-api

我想用FBConnect给我的朋友们拍照, 请求的URL是:

pictureURL =  [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?width=50&height=50", [data objectForKey:@"id"]];

图像设置在这里:

NSString *pictureUrl = [[NSString alloc] initWithFormat:@"%@", [self getProfileUrl:object]];
[friend setImage:pictureUrl];

set方法是:

NSData *pictureData = [NSData dataWithContentsOfURL:[NSURL URLWithString:pictureUrl]];
UIImage *image = [UIImage imageWithData:pictureData];
if (image != nil)
    friendImage = image;

很简单, 但对于很多朋友来说,这个过程需要太长时间, 有没有办法让个人资料图像更快,更有效?

1 个答案:

答案 0 :(得分:10)

您可以在用于检索朋友的同一请求中获取他们的个人资料照片:

/me/friends?fields=name,picture.type(large)

您收到与此相似的回复:

{   "data": [
    {
      "name": "xxx", 
      "id": "42", 
      "picture": {
        "data": {
          "url": "https://fbcdn-profile-a.akamaihd.net/image1.jpg",

          "is_silhouette": false
        }
      }
    }, 
    {
      "name": "xxx", 
      "id": "42", 
      "picture": {
        "data": {
          "url": "https://fbcdn-profile-a.akamaihd.net/image2.jpg",

          "is_silhouette": false
        }
      }
    },
...

所以你不必为你的每个朋友打电话给Facebook。此外,我建议您异步加载图像,这great component可能是一个很好的起点。