Scofield Tran Scofield Tran - 2 months ago 15
iOS Question

How to get all friend using Facebook v4

I'm using Facebook v4.0.1 to integrate into my app. I using FBSDKGraphRequest to get friend list

FBSDKGraphRequest *friendsRequest = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me/friends" parameters:nil];
FBSDKGraphRequestConnection *connection = [[[FBSDKGraphRequestConnection alloc] init] autorelease];
[connection addRequest:friendsRequest
completionHandler:^(FBSDKGraphRequestConnection *innerConnection, NSDictionary *result, NSError *error) {

}];
// start the actual request
[connection start];


It just returns around 25 friends and a param named paging to get next friends.

How can I use paging to get next or there is another way to get all friends once

Answer
"paging": {
     "previous": "me/friends?limit=25&before=NDMyNzQyODI3OTQw"
"next": "me/friends?limit=25&after=MTAxNTExOTQ1MjAwNzI5NDE="
}

The paging should include a "next" & "previous" URLs, you will want to use those URLs in-place of your original @"me/friends" string and you'll get either the page before or after the current data. If there is no longer a "next" that means that there are no more pages for you to request.

You could always try adding the limit parameter on to your first request and see what happens when you up the 25 limit to something higher. I'm not sure how many you'll be able to get away with getting at one time but at least it's an upper limit so it'll return what it can if it's over.

More paging info available here: https://developers.facebook.com/docs/graph-api/using-graph-api/v2.3#paging

Comments