-
Notifications
You must be signed in to change notification settings - Fork 266
Pagination
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 -
- Use the
getMediaForUser:withSuccess:failure:
endpoint to receive the first 'page' of data. You will receive aInstagramPaginatedInfo
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)
{
...
}];
- 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) {
...
}];
- 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.
- Just use the same call -
getMediaForUser:count:maxId:withSuccess:failure:
passing the next maxID to themaxId
parameter each time, obtained frompaginationInfo.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.