Question

I'm transferring my iOS code from YouTube Data API v2 to v3.

I would like to retrieve the number of items in a playlist with YouTube API v3.

With the data API v2, I could call a search query, resulting in a list of playlist items with the property "size", which represented the size of the playlist, see:

https://gdata.youtube.com/feeds/api/playlists/snippets?q=GoogleDevelopers&max-results=10&v=2&alt=jsonc

With API v3, I haven't found a way to achieve this. I tried queries, like below, not resulting in the desired output.

https://www.googleapis.com/youtube/v3/playlists?part=snippet&id=RD0KSOMA3QBU0&key={YOUR_API_KEY}

The only way to get the number of items is running a query for each playlist, retrieving the full playlist items. This is an overkill, however, and results in a too high API usage. https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=RD0KSOMA3QBU0&key={YOUR_API_KEY}

Any help appreciated!

Thanks

Was it helpful?

Solution

thanks for that. It helped me to find a solution, which is now to call

https://www.googleapis.com/youtube/v3/playlists?part=contentDetails&id={Comma Separated ID's}&key={YOUR_API_KEY}

an use the option to make a comma separate lists of the playlists to evaluate. In the return string, I grab the "itemCount" parameter for each playlist.

Thanks

OTHER TIPS

Unfortunately, there is no way to get number of items in a playlist without requesting contentDetails in the parts (which isn't supported when listing playlists).

I have use the following V3 api to get the playlist videos, and its works for me.

https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails&maxResults=50&playlistId=PLFPg_IUxqnZM3uua-YwStHJ1qmlQKBnh0&key={YOUR_API_KEY_HERE}

**

playlistId

**

There is no details available for "playlistId" parameter in Youtube Documentation. but is works for getting playlist videos.

This javascript will retrieve the number 91. That is the total number of clips (total = data.pageInfo.totalResults) from the youtube playlist

<script>
  function numberOfClips(pid){ 
    $.get(
        "https://www.googleapis.com/youtube/v3/playlistItems",{
        part : 'snippet', 
        maxResults : 2,
        playlistId : pid,
        key: 'YOUR API v.3 KEY',
        fields: 'pageInfo(totalResults)'        
        },
        function(data) {
             total = data.pageInfo.totalResults;
             $('#total').html('Total number of clips: ' + total);
             st = JSON.stringify(data,'',2);
             $('#area1').val(st);
        });
  }
  </script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>

<body onload="numberOfClips('PLE9F62B21C75C054C')">
  <p id="total"></p>
  <textarea id='area1' style='width:400px;height:100px;'></textarea>

PLE9F62B21C75C054C

I would not recommend to rely on neither itemsCount in Playlist-Query nor pageInfo.totalResults in Playlistitems-Query, because both values may differ from the size of the retrieved list of playlist-items

see also: https://stackoverflow.com/questions/37899490/totalresults-in-playlistitems-do-not-match-items-size

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top