I understand that youtube response contains the next and previous page tokens and we can use those to go to previous and next pages.
eg :
https://www.googleapis.com/youtube/v3/search?&key={key}&part=snippet&maxResults=20&order=viewCount&q=abc&type=video&videoDuration=long&videoType=movie&pageToken=Cd323A
My question is how can I navigate to nth page of particular search?
Please note that some people may see this is impossible. But I have seen some site implemented this.
Yes, using the YouTube API does not incur any monetary cost for the entity calling the API. If you go over your quota an 403 Error will be returned by the API.
What should I do? You can continue using the v2 API for comments and uploading video captions for now, and we'll be adding this functionality into the v3 API soon. While we don't have specific dates yet, we will release that functionality so that developers have as much time as possible to migrate to v3.
Youtube API only provides NextPageToken
and PreviousPageToken
, that's it, sorry: see documentation here: https://developers.google.com/youtube/v3/docs/videos/list
You can still make a pagination item but you will have to implement it by calling multiple times the URL, passing the NextPageToken
as pageToken
in your requestion every time, and caching results.
By the way, this question is already answered here (see the 1st point of the answer): youtube data api v3 php search pagination?
Quoting them:
In particular your case where you need 50 pages per page and you are showing 3 pagination like (1,2,NEXT) then you need to fetch results two times. Both the results you will keep in cache so for page 1 and 2 results will be retrieved from cache. For next you make it sure that you are making query google again by sending nextPageToken.
Thus to show pagination 1-n and every page 50 results then you need to make n-1 queries to google api. But if you are showing 10 results per page then you cane make single query of 50 results using which you can show first 5 pages (1-5) with the help of retrieved results and at next you should again send next page token like above.
NOTE- Google youtube api provide 50 results max.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With