6

How can we get the complete list of friends, currently I am using

[FBRequestConnection startForMyFriendsWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
    if (!error) {
    // Do stuff
    } else {
     // Throw error
    }

In the response, we get a paging and the next url. Does anyone know how we can loop through the next url's and get the complete list of friends ?

    Response has 
 paging =     {
        next = "https://graph.facebook.com/1301xxxxxx/friends?fields=id,name,username,first_name,last_name&format=json&access_token=BAAFjJBl9zZBABALFxcbix0aNe0NFOfW8mHCU4ntPaxwooYVo1L6fOWgNTMTZBqLHfxjrWBOXNLjcCwEbkBgZAJX22Ec9PlatgHP9GfjVEWyxk0qGtxxxxxxxxxx&limit=5000&offset=5000&__after_id=10000xxxxxx";
};

Thanks in advance

Ninad Shah
  • 166
  • 6

1 Answers1

0

At first you need to get link on next, you need to extract offset and __after_id parameters,according to iPhone parsing url for GET params you will get dictionary with parameters:

//put here your string with parameters
   NSString* next = @"https://graph.facebook.com/1301xxxxxx/friends?fields=id,name,username,first_name,last_name&format=json&access_token=BAAFjJBl9zZBABALFxcbix0aNe0NFOfW8mHCU4ntPaxwooYVo1L6fOWgNTMTZBqLHfxjrWBOXNLjcCwEbkBgZAJX22Ec9PlatgHP9GfjVEWyxk0qGtxxxxxxxxxx&limit=5000&offset=5000&__after_id=10000xxxxxx";
    NSArray * pairs = [next componentsSeparatedByString:@"&"];
    NSMutableDictionary * kvPairs = [NSMutableDictionary dictionary];
    for (NSString * pair in pairs) {
        NSArray * bits = [pair componentsSeparatedByString:@"="];
        NSString * key = [[bits objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        NSString * value = [[bits objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        [kvPairs setObject:value forKey:key];
    }

You can get correct parameters by kvPairs[@"__after_id"] and kvPairs[@"offset"]

Next step create add this parameters to your original request, in original request offset and after id should be nil, and you need to filter this situation, if you will do all correct, you will be able to call your ethos recursively

Community
  • 1
  • 1
oks_ios
  • 187
  • 2
  • 8
  • Also this may be helpful http://stackoverflow.com/questions/4812941/how-to-move-to-the-next-page-in-facebook-json-response-using-ios-sdk – oks_ios Jul 17 '14 at 17:39