...

/

Pagination and Other Graph API Endpoints

Pagination and Other Graph API Endpoints

Learn how to apply paging and different ways to limit the number of posts with Graph API.

Working with paged results

As you’re becoming accustomed to sending requests to the Graph API in order to fetch data, one important concept to cover is pagination. In our previous lesson, we saw our call to the /feed edge endpoint respond with additional paging data. In this section, we will get familiar with using Facebook’s paging mechanism.

Why paging?

Imagine a prolific user that has added thousands of posts to their feed. Now imagine your web server calling the /feed endpoint for that user. Getting a response with thousands of records in an array called data doesn’t sound very appealing. It is an expensive network transfer, not to mention a very unwieldy data set for practical use.

The standard approach to dealing with a large set of requested data is to break that data into pages. For example, let’s say a user has 135 posts, and a page “size” is 10 posts. That would mean this user’s posts would be divided into 13 full pages (each with 10 posts, equaling 130 posts in total) along with a 14th page with only 5 posts.

That’s the basic concept of paging: breaking a large set of requested data into smaller pages.

Facebook’s different types of paging

There are three approaches to paging used by the Facebook Graph API: cursor-based, time-based, and offset-based. Cursor and time-based pagination are more common, while offset-based pagination is the least common.

We will spend our time describing cursor-based and time-based pagination and then play around with time-based pagination just to get familiar. Once you have become accustomed to any one of these three approaches, the remaining approaches will be quite simple to pick up.

With cursor-based ...