Skip to content
Shyam Bhat edited this page May 25, 2015 · 3 revisions

Let's say we need to get a particular user's media feed in multiple pages.

You have two options to get around Pagination in InstagramKit -

Option 1

  1. Use the getMediaForUser:withSuccess:failure: endpoint to receive the first 'page' of data. You will receive a InstagramPaginatedInfo object in the response, which contains all the information you need to make your next paginated call.
InstagramEngine *engine = [InstagramEngine sharedEngine];
[engine getMediaForUser:user 
            withSuccess:^(NSArray *media, InstagramPaginationInfo *paginationInfo) 
            {
                if (paginationInfo) {
                    self.currentPaginationInfo = paginationInfo;
                }
                ...
            } 
               failure:^(NSError *error) 
            {
                ...
            }];
  1. Pass this paginationInfo object to the getPaginatedItemsForInfo:withSuccess:failure: method, to receive your paginated feed as response.
[engine getPaginatedItemsForInfo:self.currentPaginationInfo
                     withSuccess:^(NSArray *media, InstagramPaginationInfo *paginationInfo) 
                 {
                       if (paginationInfo) {
                             self.currentPaginationInfo = paginationInfo;
                       }
                       ...
                 }
                 failure:^(NSError *error, NSInteger statusCode) {
                       ...
                 }];
  1. The paginated feed comes with a new paginationInfo object of it's own, pass the newest each time to getPaginatedItemsForInfo:withSuccess:failure: for subsequent pagination calls.

Option 2 (Recommended)

  1. Just use the same call - getMediaForUser:count:maxId:withSuccess:failure: passing the next maxID to the maxId parameter each time, obtained from paginationInfo.nextMaxId of the newest paginationInfo object.
[engine getMediaForUser:user.Id 
                  count:15 
                  maxId:self.currentPaginationInfo.nextMaxId 
            withSuccess:^(NSArray *media, InstagramPaginationInfo *paginationInfo) 
               {
                     if (paginationInfo) {
                         self.currentPaginationInfo = paginationInfo;
                     }
                     ...
               } 
               failure:^(NSError *error) 
               {
                     ...
               }];

The first request will go with maxId as nil.

Each endpoint in the Instagram API that supports pagination, usually supports a count parameter. You can use this method and pass a count parameter to each paginated request. You can also use it in cases where you do not need pagination, but need to specify a feed count to the first request.

Clone this wiki locally