Implementation: Pagination
Stay organized with collections
Save and categorize content based on your preferences.
The following example shows how to retrieve additional sets of results for YouTube Data API (v3) queries.
The API uses the maxResults
parameter to indicate how many items should be included in an API response. Almost all of the API's list
methods (videos.list
, playlists.list
, etc.) support that parameter.
If additional results are available for a query, then the API response will contain either a nextPageToken
property, a prevPageToken
property, or both. Those properties' values can then be used to set the pageToken
parameter to retrieve an additional page of results.
For example, the following query retrieves search results for the 10 most viewed videos matching the query "skateboarding dog":
https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.search.list?
part=snippet
&maxResults=10
&order=viewCount
&q=skateboarding+dog
&type=video
The API response contains the first 10 matches for the query as well as a nextPageToken
property that can be used to retrieve the next 10 results:
The query below retrieves the next 10 results for the query:
https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.search.list?
part=snippet
&maxResults=10
&order=viewCount
&pageToken=CAoQAA
&q=skateboarding+dog
&type=video
Note: You may need to update the value of the pageToken
parameter to complete this request in the APIs Explorer. Execute the query that retrieves the first 10 results to obtain the correct pageToken
parameter value.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2022-11-04 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2022-11-04 UTC."],[[["The YouTube Data API (v3) uses the `maxResults` parameter to determine the number of items returned in a query response."],["API `list` methods, such as `videos.list` and `playlists.list`, support the `maxResults` parameter for pagination."],["If more results are available, the API response includes `nextPageToken` and/or `prevPageToken` properties."],["These token values can be used to set the `pageToken` parameter to retrieve additional result pages."],["The initial request fetches the first page of results, and subsequent requests use the `pageToken` from the previous response to get the next page of results."]]],[]]