Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change page results with YouTube Data API v3

I'm trying to get video data from the YouTube API (v3) using this example:

https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.search.list?part=snippet&maxResults=25&order=relevance&q=site%253Ayoutube.com&topicId=%252Fm%252F02vx4&_h=1&

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?

like image 754
viktor Avatar asked Jan 05 '13 15:01

viktor


People also ask

Is YouTube data API v3 free?

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.

Can you still use YouTube API v2?

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.

How do I interact with YouTube API?

After creating your project, make sure the YouTube Data API is one of the services that your application is registered to use: Go to the API Console and select the project that you just registered. Visit the Enabled APIs page. In the list of APIs, make sure the status is ON for the YouTube Data API v3.


1 Answers

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} 
like image 161
Matt Koskela Avatar answered Oct 08 '22 18:10

Matt Koskela