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

4

1 回答 1

0

首先你需要获取下一个链接,你需要提取偏移量和 __after_id 参数,根据iPhone 解析 GET 参数的 url你会得到带有参数的字典:

//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];
    }

您可以通过 kvPairs[@"__after_id"] 和 kvPairs[@"offset"] 获得正确的参数

下一步创建将此参数添加到您的原始请求中,在原始请求偏移量和 id 之后应该为 nil,并且您需要过滤这种情况,如果您做的一切正确,您将能够递归调用您的精神

于 2014-07-17T17:33:28.940 回答