Pagination
The SDKs provide two distinct methods, each suited to different use cases and requirements. Selecting the most efficient method is important for optimizing the performance of your application:
- Iterative pagination: Choose this method mainly when your application must retrieve a large number of items.
- Direct pagination: Choose this method mainly when the total number of items is manageable, or you must fetch a single page of results.
Iterative pagination
Python
Node.js
To retrieve the first page of results, invoke the search.query
method:
To retrieve subsequent pages of results, use the iterator protocol:
Use the page_limit
parameter to specify a limit of items on each page. The example below sets the limit to 5:
When the response is grouped by video, you can use the page_limit
parameter to specify the number of videos the platform will return on each page. The following example code sets the page limit to three and specifies that the result must be grouped by video:
Direct pagination
Python
Node.js
To retrieve the first page of results, invoke the search.query
method:
The response will contain an object named page_info
containing the following properties:
limit_per_page
: The maximum number of results per page.total_results
: The total number of results.page_expires_at
: The time when the current page expires.next_page_token
: A token you can use to retrieve the results on the next page. The platform doesn’t return this field when you’ve reached the end of the datasetprev_page_token
: A token you can use to retrieve the results on the previous page. The platform doesn’t return this field when you’ve retrieved the first page.
To retrieve a specific page of results, invoke the search.by_page_token
method, passing the next_page_token
property of the page_info
object as the value of the page_token
parameter. The response will be similar to the one returned when retrieving the first page of results. When the platform does not return the next_page_token
field, you’ve reached the end of the dataset.
Use the page_limit
parameter to specify a limit of items on each page. The example below sets the limit to 5:
Note
When the response is grouped by video, you can use the page_limit
parameter to specify the number of videos the platform will return on each page.