【问题标题】:Facebook API Pagination doesn't workFacebook API 分页不起作用
【发布时间】:2014-03-19 18:09:27
【问题描述】:

我使用适用于 iOS 的 Facebook SDK 3.10.0。当我试图获取用户新闻源时,我遇到了一个问题: 脸书要求:

[FBRequest requestForGraphPath:@"me/home"]

我收到所有我需要的数据和有关分页的信息的响应:

data = (
    "A LOT OF USER DATA"
);
paging =     {
    next = "https://graph.facebook.com/{MY_USER_ID}/home?format=json&access_token={ACCESS_TOKEN}&limit=25&until=1385113385";
    previous = "https://graph.facebook.com/{MY_USER_ID}/home?format=json&access_token={ACCESS_TOKEN}&limit=25&since=1385206398&__previous=1";
};

但是当我尝试使用 next 链接和 AFHTTPRequestOperation 获取信息时:

AFHTTPRequestOperation *newDataOperation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    newDataOperation.responseSerializer = [AFJSONResponseSerializer serializer];
    [newDataOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"%@", responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Next page retrieving error = %@", error);
    }];

我得到空的json

data =     (
);

我正在使用 Facebook 访问令牌调试器和结果:

我使用 Graph Api Explorer 获得的访问令牌与我在应用程序中获得的访问令牌不同。我从 Graph Api Explorer 获得的令牌工作得很好,但是当我从应用程序测试令牌时结果相同:me/home 工作 但 next 链接返回空:

【问题讨论】:

    标签: ios objective-c facebook facebook-graph-api


    【解决方案1】:
    And there is strange thing access token which i get using Graph Api Explorer
    differs from which i get in my app.
    

    其实并不奇怪。访问令牌将根据您从资源管理器右上角选择的应用程序类型而变化。

    Facebook API Pagination doesn't work
    

    我在Graph API中看到了很多关于分页问题的问题,奇怪的是问题还没有解决!您可以尝试使用Offset based pagination。例如,在 URL 中设置 limit=100&offset=0。我知道这在新闻提要的情况下没有意义,但在大量数据的情况下通常可以正常工作。

    【讨论】:

    • 发现类似问题link
    • 我不明白为什么应请求 /me/home Graph Api Explorer 应用程序返回链接 next 有效,但是当我选择我的应用程序时在 Graph Api Explorer 链接 next 中不返回任何数据... o_O
    • 我知道。有一些错误。你会在 SO 上看到很多关于它的问题,没有任何具体的答案。
    【解决方案2】:

    对于facebook的分页,我建议使用apple native class as

    如果 nextPageURL 不为零,则使用 nextPageURL 变量缓存 JSON 响应中的下一个 url,并在下一个 api 请求上分配给 url 字符串,并使用以下代码:

    if (self.nextPageURL) {
        // urlString is the first time formulated url string
        urlString = self.nextPageURL;
    }
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:urlString]];
    [NSURLConnection sendAsynchronousRequest:request queue:networkQueue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
        if (error) {
            DDLogVerbose(@"FACEBOOK:Connection error occured: %@",error.description);
        }else{
            isRequestProcessing = NO;
            NSDictionary *resultData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
            DDLogVerbose(@"parsed data is %@",resultData);
            self.nextPageURL = resultData[@"paging"][@"next"];
            // do your customisation of resultData here.
        }
    }];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多