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.

Get hands-on with 1400+ tech skills courses.