iOS中的访问分页 - 上一页和下一页:从facebook graph-api以JSON格式检索 [英] Access paging in iOS - previous and next : retrieved in JSON from facebook graph-api

查看:149
本文介绍了iOS中的访问分页 - 上一页和下一页:从facebook graph-api以JSON格式检索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从JSON上一页和下一页链接访问iOS代码中的分页

Access paging in iOS Code from JSON previous and next link

在图表api中检索的JSON对象中,由于信息的大量信息被分页,当我尝试要访问上一个和下一个链接,它会产生OAuth错误。
任何人都可以通过iOS应用中的目标C帮助您访问该链接。

In JSON object retrieved from graph api, due to loads of information the information is paged, when I try to access the previous and next link it gives OAuth error. Can anyone help in how to access the link through objective C in iOS app.

我想知道两件事 - 如何使用N来检索'N'项目 - > limit = N
以及如何打开FBSDKgraphrequest并使用分页链接链接(包含分页信息)

I want to know two things - how to retrive 'N' items using --> limit=N and how to open a FBSDKgraphrequest and using the paged link link (containing the paging information)

    paging =         {
        next = "https://graph.facebook.com/v2.3/897401690298128/inbox?access_token=CAAEsxMhiSe4BACWnj27BT6ZBvj2BAxNZCtCNQyCKQORXyylXXkQy3DLSF75UGSz2FydAkQx6Pj49MOS0Q3SGiU1vkQ1iUEs2fQvvlwW3Wc04DEnXZB4CZCza7tOJfyncIPrkFrudQCeRhWUUREqMpCI8Dnm6Ozc6xmwOlT1uN2ZCgQ91llcVC1kV04fiZCqO6H6edFe2YZAUZBy86pw1p4SWCUvgMshzkvZBGgpG8UWG50ZCShdeQPUc86fsuQGOcAno0ZD&limit=25&until=1428241306&__paging_token=enc_AdC9127ZCBVnZACHUlMZBTC39ZC8bSP4ZA8uwQZBdy8xhsZAyKAcxxNdqn48Er3CrVM4DkJPATHhOYBVRm8FuCvYZBU8KSpZA";
        previous = "https://graph.facebook.com/v2.3/897401690298128/inbox?access_token=CAAEsxMhiSe4BACWnj27BT6ZBvj2BAxNZCtCNQyCKQORXyylXXkQy3DLSF75UGSz2FydAkQx6Pj49MOS0Q3SGiU1vkQ1iUEs2fQvvlwW3Wc04DEnXZB4CZCza7tOJfyncIPrkFrudQCeRhWUUREqMpCI8Dnm6Ozc6xmwOlT1uN2ZCgQ91llcVC1kV04fiZCqO6H6edFe2YZAUZBy86pw1p4SWCUvgMshzkvZBGgpG8UWG50ZCShdeQPUc86fsuQGOcAno0ZD&limit=25&since=1432299972&__paging_token=enc_AdDp9ZCK2ZBP40AgTi4TCzaB0QFT1Cy7s1R7HLLDDaT7nbnLYDZB4LZBjiONOqG5QR9Q22KY1oU1LzNOwS5uNZBG7uLF4&__previous=1";
    };


推荐答案

页面信息具有当前访问令牌,并且还取决于不同的限制限制寻呼值将始终改变,所以;最好使用url并获取结果。
因为next的结果也会有指向前一个和下一个的指针,所以解析获得的结果的最佳方法是通过递归函数调用它并在调用函数外部和内部传递分页的下一个值来遍历所有页面。
不要忘记在想要停止遍历其他节点的地方设置限制。
例如:

Page information has the current access token, and also depending up different limits restriction paging values will always change , so; its best to use the url and fetch the result. Because the result of next will also have pointer to both previous and next , best method to parse the result obtained is by calling it through a recursive function and passing the paging next values outside and inside the calling function to traverse all pages. Don't forget to put a restriction where you want to stop traversing other nodes. eg:

        NSURL *url = [NSURL URLWithString:PagingNext];
        NSURLRequest *request = [NSURLRequest requestWithURL:url];
        [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *errorConnection)
         {
             if(errorConnection == nil)
             {
                 NSError *error;
                 id result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
                 if (result == nil)
                 {
                     NSLog(@"Error parsing JSON:\n%@",error.userInfo);
                     return;
                 }
                 //if no error then extract paging next and do what you want -> 
                 /*
                    result = {
                                data[20],
                                paging={
                                       previous= "URL_of_previous"
                                       next = "URL_of_next"
                                       }
                             }
                 */
                 if ([result isKindOfClass:[NSDictionary class]])
                 {
                     NSArray * data = [result objectForKey:@"data"];
                     NSDictionary *paging =[result objectForKey:@"paging"];
                     NSString * resultPagingNext = [paging objectForKey:@"next"];

                     [self call_method_recursively_with_parameter_of_next_page:data pagingNext:resultPagingNext];
                 }
             }
             else
             {
                 NSLog(@"Connection Error:\n%@", errorConnection.userInfo);
                 UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Network Issue"
                                                                                          message:@"Check if you are connected to Internet" preferredStyle:UIAlertControllerStyleAlert];
                 UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
                                            {
                                                NSLog(@"User has pressed OK."); }];
                 [alertController addAction:okAction];
                 [self presentViewController:alertController animated:YES completion:nil];
             }
         }];

这篇关于iOS中的访问分页 - 上一页和下一页:从facebook graph-api以JSON格式检索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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