Reputation: 105
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?
Upvotes: 1
Views: 3339
Reputation: 881
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.
Upvotes: 10