我正在尝试从 Facebook 获取“taggable_friends”列表,其中可能有超过 1000 个可标记的 friend ,因此 Facebook 对结果进行了分页。这是方法。
-(void)getsFbTaggableFriends:(NSString *)nextCursor dicFBFriends:(NSMutableArray *) dicFriends failure:(void (^) (NSError *error))failureHandler
{
NSString *qry = @"/me/taggable_friends";
NSMutableDictionary *parameters;
if (nextCursor == nil) {
parameters = nil;
}
else {
parameters = [[NSMutableDictionary alloc] init];
[parameters setValue:nextCursor forKey:@"next"];
}
[FBRequestConnection startWithGraphPath:qry
parameters:parameters
HTTPMethod:@"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
if (error) {
NSLog(@"%@", [error localizedDescription]);
}else {
/* handle the result */
NSMutableDictionary *mDicResult = [[NSMutableDictionary alloc]initWithDictionary:result];
for (NSDictionary * fbItem in [mDicResult valueForKey:@"data"])
{
[dicFriends addObject:fbItem];
}
// if 'next' value is found, then call recursively
if ([[mDicResult valueForKey:@"paging"] objectForKey:@"next"] != nil) {
NSString *nextCursor = mDicResult[@"paging"][@"next"];
NSLog(@"next:%@", [nextCursor substringFromIndex:27]);
[self getsFbTaggableFriends:nextCursor dicFBFriends:dicFriends failure:^(NSError *error) {
failureHandler(error);
}];
}
}
}];
}
问题: 我在“结果”对象中获得了前 1000 条记录,并且“下一个”键的值作为递归调用的“参数”参数传递。但是,第二次迭代不会分页并继续返回相同的 1000 条记录。
我还尝试使用 nextCursor
值作为第二次调用的 startWithGraphPath
参数。它产生了一个不同的响应对象,其中包含 og_object
、share
、id
而不是 data
和 分页
.
请帮助正确地逐页获取可标记的 friend ,只要响应对象中存在“下一个”值。谢谢。
最佳答案
使用返回的next
端点(Graph路径部分,包括光标)作为后续请求的新Graph路径,而不是将其作为参数。
关于iOS:使用 'next' 分页获取 Facebook 好友,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29909534/