iOS:使用“下一个”获取分页的Facebook朋友 [英] iOS: fetch Facebook friends with pagination using 'next'

查看:114
本文介绍了iOS:使用“下一个”获取分页的Facebook朋友的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Facebook获取taggable_friends列表,其中可能有超过1000个可贴标签的朋友,所以Facebook分页结果。 (NSString *)nextCursor dicFBFriends:(NSMutableArray *)dicFriends失败:() void(^)(NSError * error))failureHandler
{
NSString * qry = @/ me / taggable_friends;
NSMutableDictionary *参数;

if(nextCursor == nil){
parameters = nil;
}
else {
parameters = [[NSMutableDictionary alloc] init];
[参数setValue:nextCursor forKey:@next];



[FBRequestConnection startWithGraphPath:qry
参数:参数
HTTPMethod:@GET
completionHandler:^(
FBRequestConnection * connection,
id result,
NSError * error
){
if(error){
NSLog(@%@,[error localizedDescription] );

} else {
/ *处理结果* /
NSMutableDictionary * mDicResult = [[NSMutableDictionary alloc] initWithDictionary:result];

for(NSDictionary * fbItem in [mDicResult valueForKey:@data])
{
[dicFriends addObject:fbItem];
}
//如果找到next值,则递归调用

if([[mDicResult valueForKey:@paging] objectForKey:@next]! = nil){

NSString * nextCursor = mDicResult [@paging] [@next];
NSLog(@next:%@,[nextCursor substringFromIndex:27]);

[self getsFbTaggableFriends:nextCursor dicFBFriends:dicFriends failed:^(NSError * error){
failureHandler(error);
}];
}
}
}];
}

问题:
我在结果中获得前1000条记录对象,next键的值作为递归调用的parameters参数传递。但是,第二次迭代不分页继续返回相同的1000条记录。



我还尝试使用 nextCursor 值作为 startWithGraphPath 参数为第二个调用。它导致了一个不同的响应对象,其中包含诸如 og_object share id 而不是数据& 分页



请帮助逐页正确获取标记的朋友,只要下一个值为存在于响应对象中。谢谢。

解决方案

使用返回的下一个端点(图形路径部分,包括光标)作为后续请求的新图形路径,而将其作为参数。


I am trying to fetch 'taggable_friends' list from Facebook, where there may be more than 1000 taggable friends, so Facebook paginates the results. Here is the method.

-(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);
                                      }];
                                  }
                              }
                          }];
}

Problem: I get first 1000 records in the 'result' object and the value of the 'next' key is passed as the "parameters" parameter for the recursive call. However, the second iteration doesn't paginate & keeps returning the same 1000 records.

I also tried using the nextCursor value as the startWithGraphPath parameter for the second call instead. It resulted in a different response object with keys like og_object, share, id instead of data & paging.

Please help to properly obtain the taggable friends page by page, as long as 'next' value is present in the response object. Thank you.

解决方案

Use the returned next endpoint (Graph path portion, including the cursor) as the new Graph path for the subsequent request, instead putting it as the parameter.

这篇关于iOS:使用“下一个”获取分页的Facebook朋友的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆