简体   繁体   中英

Getting facebook friends profile pictures the fastest way - iOS

I am trying to get my friends pictures with FBConnect, The requested URL is:

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

And the image set here:

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

the set method is:

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

Very simple, But for a big amount of friends this process takes tooooooo long, Is there a way to get the profile images faster, or more efficient than this?

You could get their profile picture in the same request you use to retrieve your friends like this:

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

You get a response similar to this one:

{   "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
        }
      }
    },
...

So you don't have to call Facebook for each of your friends. Also, i suggest you load your images asynchronously and this great component could be a good starting point.

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