iOS:使用 'next' 分页获取 Facebook 好友

标签 ios facebook facebook-graph-api pagination next

我正在尝试从 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_objectshareid 而不是 data分页.

请帮助正确地逐页获取可标记的 friend ,只要响应对象中存在“下一个”值。谢谢。

最佳答案

使用返回的next端点(Graph路径部分,包括光标)作为后续请求的新Graph路径,而不是将其作为参数。

关于iOS:使用 'next' 分页获取 Facebook 好友,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29909534/

相关文章:

facebook - 今天有人真的有 Facebook 图形洞察 api 工作吗?

c# - 如何使用手机摄像头作为背景?

安卓/ Facebook : Post message on wall

facebook - Cordova Facebook Like 按钮覆盖 Webview

facebook-graph-api - 在墙上分享帖子的详细信息

facebook sdk/graph api - 获取自定义受众当前大小?

ios - LaunchScreen 不适用于不同的设备

iphone - 通过AVAudioRecorder录制声音

ios - 是否应该通过storyboard/xib添加可选 View ,然后以编程方式隐藏或添加? (良好做法)

java - 在 Android 应用程序中检索 Facebook 用户的个人资料图片时出现空指针