Facebook Graph API - Batch Request for large profile pictures

1.6k Views Asked by At

Trying to grab all of the users Facebook friends information which I can successfully do via a batch request:

NSString *jsonRequest1 = @"{ \"method\": \"GET\", \"relative_url\": \"me/friends?fields=name,picture\" }";
NSString *jsonRequestsArray = [NSString stringWithFormat:@"[%@]", jsonRequest1];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObject:jsonRequestsArray forKey:@"batch"];
[facebook requestWithGraphPath:@"me" andParams:params andHttpMethod:@"POST" andDelegate:self];

The profile pictures are small in size (50x50) and i need to specify the size of the photos. I've been looking at the graph API docs and i'm struggling to tie the two together - here's the related link: http://developers.facebook.com/docs/reference/api/user/

It says to add the following parameters to the request but like i said, i'm not sure how to tie the two together:

picture?type=large

I'm sure it would work for a single request for a particular user but i'm having no luck through a batch request.

Thanks for your help, it's probably staring me in the face!

4

There are 4 best solutions below

0
On

This is possible by adding a height and width parameter to the URL. FB will attempt to provide you an image that matches your width and height criteria. Your batch would look something like this:

var batch= {
  batch: []
};

batch.batch.push({
  method: 'GET',
  relative_url: fbid + '/picture?height=400&width=400'
});

FB.api('/', 'POST', batch, function (response) {
});
8
On

I don't think there is an easy way to do this using the Graph API. It is easy with this FQL query (which can be passed via a batch request):

SELECT uid, name, pic_big FROM user WHERE uid IN 
  (SELECT uid2 FROM friend WHERE uid1 = me())

If you're looking for a specifically sized picture, take a look at the new profile_pic table.

0
On

Something like that works for me:

{
"friends": "SELECT uid, name, pic_big FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())",
"profiles": "SELECT id, url, real_width, real_height FROM profile_pic WHERE id IN (SELECT uid FROM #friends) AND width = 300"
}

It's not perfect (two queries to scan) but it' one request.

Based on profile_pic table documentation.

Can be tested in FQL Explorer.

0
On

The FQL has some advantage like Facebook stated

FQL, the Facebook Query Language, allows you to use a SQL-style interface to query data exposed by the Graph API. It provides advanced features not available in the Graph API, including batching multiple queries into a single call.

Take a look at this tutorial from Facebook.

https://developers.facebook.com/docs/howtos/run-fql-queries-ios-sdk/

But I suggest to use Graph API with Field Expansion, this is very helpful and easier to understand than FQL. Note that Graph API doesn't support for all subfields.

https://developers.facebook.com/docs/reference/api/field_expansion/

Good luck man!