0

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!

user1168056
  • 401
  • 8
  • 19
  • You are confusing the `picture` _property_ of the user object with the `picture` _connection_ here – those are to different things, and specifying the size via `type` parameter only works for the latter. – CBroe Aug 28 '12 at 11:13

4 Answers4

2

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!

Minh Phan
  • 49
  • 1
  • 6
1

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.

cpilko
  • 11,792
  • 2
  • 31
  • 45
  • Really? That's a shame, would of thought Facebook would accommodate for a request like this. How do apps such as Songpop/Draw Something do it? I'm pretty sure they don't scroll through each User ID, and the images are definately better quality than 50x50. I literally have no experience with FQL, do you have any pointers how to translate your approach into a HTTP request using Facebook's ethos? – user1168056 Aug 27 '12 at 18:22
  • You can make an FQL query using a `relative_url` of `method/fql.query?query=URL_ENCODED_QUERY`. See the "Using fql.query..." part of the docs for more info: https://developers.facebook.com/docs/reference/api/batch/ – cpilko Aug 27 '12 at 18:28
  • Doesn't really make any sense to me. When i say no experience, i literally mean no experience :D I'll look into it, don't know what the hell im doing though. Cheers for your help. – user1168056 Aug 27 '12 at 18:39
  • If you're making just one request at a time, you don't need to use batch requests. That makes everything easier, and you can use the FQL endpoint of the API calls. Take a look at the [Graph API Explorer](https://developers.facebook.com/tools/explorer) too. Good luck. – cpilko Aug 27 '12 at 18:44
  • That's why i'm having an issue, i'm showing all of the user's friends with profile pictures, it would take hundreds of requests to get high quality profile picture images for each friend, so one request at a time is simply not feaseable. Anyway, i've tried the following, no luck! NSString *jsonRequest1 = @"{\"method\":\"POST\",\"relative_url\":\"method/fql.query?query=SELECT+uid+name+pic_big+FROM+user+WHERE+uid+IN+(SELECT+uid2+FROM+friend+WHERE+uid1=me())\",}"; – user1168056 Aug 27 '12 at 18:49
  • You only need one call with FQL. That will get you all your friend's pictures. See here: http://bit.ly/PMuzT3. I don't know xcode, so I can't help you with that syntax. – cpilko Aug 27 '12 at 19:12
  • Ah right, that's what i'm having trouble with. Is there any way to send an FQL query as GET (ie just a URL)? – user1168056 Aug 27 '12 at 19:29
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/15868/discussion-between-cpilko-and-user1168056) – cpilko Aug 27 '12 at 19:37
1

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) {
});
Kris Range
  • 11
  • 1
0

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.

Grzegorz Gierlik
  • 11,112
  • 4
  • 47
  • 55