iOS FBRequestConnection startForMyFriendsWithCompletionHandler获取完整的好友列表

Nin*_*hah 6 facebook ios

我们如何获得目前正在使用的完整朋友列表

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

在响应中,我们得到一个分页和下一个url.有谁知道我们如何循环下一个网址并获得完整的朋友列表?

    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";
};
Run Code Online (Sandbox Code Playgroud)

提前致谢

小智 0

首先你需要获取next的链接,你需要提取offset和__after_id参数,根据iPhone解析url的GET参数你将得到带有参数的字典:

//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];
    }
Run Code Online (Sandbox Code Playgroud)

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

下一步创建将此参数添加到您的原始请求中,原始请求中的 offset 和 id 之后应该为零,并且您需要过滤这种情况,如果您全部正确,您将能够递归地调用您的ethos