How to change page results with YouTube Data API v3
Solution 1
If you look at the results, you will see a "nextPageToken" item right after "pageInfo". This needs to be passed as the pageToken on your next request.
So if you make a call to this api:
https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=25&order=relevance&q=site%3Ayoutube.com&topicId=%2Fm%2F02vx4&key={YOUR_API_KEY}
You would make a call to this one for the next page:
https://www.googleapis.com/youtube/v3/search?pageToken=CBkQAA&part=snippet&maxResults=25&order=relevance&q=site%3Ayoutube.com&topicId=%2Fm%2F02vx4&key={YOUR_API_KEY}
Solution 2
For example this is your api
Here with this api you will get result like
{
"kind": "youtube#playlistListResponse",
"etag": "\"XpPGQXPLgenD_n8JR4Qk/05DoUs3OS-AxnDI1FJbdM\"",
"nextPageToken": "CDIQAA",
"pageInfo": {
"totalResults": 585,
"resultsPerPage": 50
},
"items": [
{
"kind": "youtube#playlist",
"etag": "\"XpPGQXPLgenD_n8JR4Qk/7m0ztlwxvPmRtXjs\"",
.........
.........
In this result see "nextPageToken": "CDIQAA",
Now add pageToken parameter to your api
EX:
Now this is your result, you will get nextPageToken and prevPageToken
{
"kind": "youtube#playlistListResponse",
"etag": "\"XpPGQX4Qk/R3A6jpxuE\"",
"nextPageToken": "CGQQAA",
"prevPageToken": "CDIQAQ",
"pageInfo": {
"totalResults": 585,
"resultsPerPage": 50
},
"items": [
{
"kind": "youtube#playlist",
"etag": "\"XpPGQXR4Qk/XsatNRtxJQ\"",
.........
.........
viktor
Updated on March 20, 2020Comments
-
viktor about 4 years
I'm trying to get video data from the YouTube API (v3) using this example:
The problem is that I don't understand how to change the page results. For example this query gives me 25 items (maxResults=25) but total results are --> "totalResults": 548669. So the big question here is how to move on page 2 and receive the other 25 results?
-
Moji over 8 yearshow do we know we have reached the end of all results?
-
krzysiej over 8 yearslast page don't have nextPageToken
-
Mustafa over 8 yearsYa there is no nextPageToken in the first request with v3 api
-
Mustafa over 8 years@krzysiej i also didnt get the
nextPageToken
returned. but i removedfields
param in my request and i got the next page . so try just including your query and your key as a param in your http request . it will work -
Matt Koskela over 8 years@MurWade I believe krzysiej was just explaining to Manoj Sharma that the last page of results will not have a nextPageToken.
-
Georgi Kovachev over 7 yearsHow can I move to specific Page? Let's say 10th page?
-
Matt Koskela over 7 years@GeorgiKovachev that doesn't appear to be supported, but you could use the publishedAfter and publishedBefore parameters to limit the items you're receiving as an alternative to starting 10 pages deep (depending on your specific use case, of course)
-
puretppc over 6 yearsI wanna list all results at once so I need to get each and every individual nextPageToken? How do I fetch all of the pageToken IDs then?
-
Matt Koskela over 6 years@puretppc - you need to programmatically call the API using the nextPageToken in each call until there is no more nextPageToken (meaning you're on the last page)
-
Matt Koskela over 4 yearsYes, every resource you request will count against your quota. Only request the “parts” that you need to limit the number of units you are using against that quota.
-
user123456 almost 4 yearsbut why results per page always 50 @iOS