【问题标题】:iOS FBRequestConnection startForMyFriendsWithCompletionHandler getting complete list of friendsiOS FBRequestConnection startForMyFriendsWithCompletionHandler 获取完整的朋友列表
【发布时间】:2012-10-20 23:47:43
【问题描述】:

如何获取好友的完整列表,目前我正在使用

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

在响应中,我们得到一个分页和下一个 url。有谁知道我们如何遍历下一个 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";
};

提前致谢

【问题讨论】:

    标签: ios facebook


    【解决方案1】:

    首先你需要在next上获取链接,你需要提取offset和__after_id参数,根据iPhone parsing url for GET params你会得到带参数的字典:

    //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,并且您需要过滤这种情况,如果您做的一切正确,您将能够递归调用您的精神

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 2013-04-21
    • 1970-01-01
    • 2014-11-14
    相关资源
    最近更新 更多