{"id":258,"date":"2016-04-17T08:45:49","date_gmt":"2016-04-17T08:45:49","guid":{"rendered":"http:\/\/ootips.org\/yonat\/?p=258"},"modified":"2016-04-17T08:49:20","modified_gmt":"2016-04-17T08:49:20","slug":"paging-facebook-graph-results","status":"publish","type":"post","link":"https:\/\/ootips.org\/yonat\/paging-facebook-graph-results\/","title":{"rendered":"Paging Facebook Graph Results"},"content":{"rendered":"<p>Facebook iOS SDK provides `FBSDKGraphRequest` to get friends, posts, etc. But the results are paged: you only get the first 25 friends (or 5 posts). To get the rest you need to send a new request, not provided by `FBSDKCoreKit`:<\/p>\n<pre class=\"lang:swift decode:true \">\r\n[graphRequest startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {\r\n\t\/\/ first handle error and result...\r\n\t\/\/ then get the next page of results:\r\n\tNSString *nextPage = json[@\"paging\"][@\"next\"];\r\n\tif (nextPage) {\r\n\t\t[[[NSURLSession sharedSession] dataTaskWithURL:[NSURL URLWithString:nextPage] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {\r\n\t\t\t\/\/ parse data, handle results, and get the next page recursively.\r\n\t\t}] resume];\r\n\t}\r\n}];\r\n<\/pre>\n<p>To simplify this, I wrote a simple extension to `FBSDKGraphRequest` that handles paging: <a href=\"https:\/\/gist.github.com\/yonat\/0a37ccb89adfc8f92d740e8549093d14\" target=\"_blank\">FBSDKGraphRequest+Paging<\/a>. Feel free to use it.<\/p>\n<p>Usage:<\/p>\n<pre class=\"lang:swift decode:true \">\r\nFBSDKGraphRequest *friendsRequest = [[FBSDKGraphRequest alloc] initWithGraphPath:@\"\/me\/friends\" parameters:nil];\r\n[friendsRequest startPagingWithCompletionHandler:^(id result, NSError *error) {\r\n    \/\/ check for error...\r\n    \/\/ use parsed result:\r\n    NSArray *friends = result[@\"data\"];\r\n}];\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Facebook iOS SDK provides `FBSDKGraphRequest` to get friends, posts, etc. But the results are paged: you only get the first 25 friends (or 5 posts). To get the rest you need to send a new request, not provided by `FBSDKCoreKit`: &hellip; <a href=\"https:\/\/ootips.org\/yonat\/paging-facebook-graph-results\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[1],"tags":[7,6,13,14],"class_list":["post-258","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-ios","tag-iphone","tag-objective-c","tag-sample-code"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2aEUP-4a","_links":{"self":[{"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts\/258","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/comments?post=258"}],"version-history":[{"count":3,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts\/258\/revisions"}],"predecessor-version":[{"id":261,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts\/258\/revisions\/261"}],"wp:attachment":[{"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/media?parent=258"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/categories?post=258"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/tags?post=258"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}