Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How get all videos from a playlist using youtube api?

Now i am using this link

http://gdata.youtube.com/feeds/api/playlists/plalistID

to retrieve video from YouTube playlist. but the problem is only getting 25 video. but the playlist contains 100 videos. How get all video from playlist?

like image 726
crynaldo madrid Avatar asked Nov 13 '12 09:11

crynaldo madrid


2 Answers

Youtube let's you fetch up to 50 entries per request.
The response contains some <link> elements. And if there are still more records to fetch one of it is of the form <link rel='next' ... e.g.

<link
  rel='next'
  type='application/atom+xml'
  href='https://gdata.youtube.com/feeds/api/playlists/plalistID?start-index=26&amp;max-results=25&amp;v=2'
/>

Search for this element and retrieve the document that the href attribute points to until the repsonse has no <link rel='next' element.

like image 37
VolkerK Avatar answered Sep 17 '22 06:09

VolkerK


YouTube API v3

You need to request the PlaylistItems > list feed:

https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=25&playlistId=PLVfin74Qx3tV8bgAhzbfDpnfPoGmJWAcn&key=YOUR_API_KEY

The JSON returned by the API will contain these properties:

  • nextPageToken
  • prevPageToken

Pass one of these values in the pageToken query string parameter to retrieve the next or previous "page" in the result set:

https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=25&playlistId=PLVfin74Qx3tV8bgAhzbfDpnfPoGmJWAcn&pageToken=xxYYzz&key=YOUR_API_KEY

The JSON also contains pageInfo.resultsPerPage and pageInfo.totalResults properties.


YouTube API v2 answer is here.

like image 87
Salman A Avatar answered Sep 20 '22 06:09

Salman A