Retrieving list of video information for an auto-generated YouTube playlist using v3 API -
// first attempt @ using youtube's v3 api. doesn't require authentication. getautogeneratedplaylistdata: function() { gapi.client.setapikey('{api_key}'); gapi.client.load('youtube', 'v3', function () { var request = gapi.client.youtube.playlistitems.list({ part: 'contentdetails', maxresults: 50, playlistid: 'alyl4ky05133rtmhtulsaxkj_y6el9q0jh', fields: 'items/contentdetails' }); request.execute(function (response) { console.log("response:", response); }); }); }
this code takes playlistid of auto-generated youtube playlist , retrieves first 50 items it.
the provided response's contentdetails contains each video's id.
it seems if want retrieve of video information auto-generated playlist need issue 2n requests youtube? n requests retrieve of video ids playlist in sets of no more 50. once have of video ids... need ask youtube video information of videos. can data 50 videos in 1 request... that's n requests youtube retrieve of videos?
this seems poor design decision. previously, using v2 api, if retrieving of information playlist sent necessary information videos in initial request.
is no longer possible using v3 api? supposed incur o(2n) network costs...? really?
what additional video information after? if need publication date, title, description, thumbnails, position in playlist, etc., in snippet of playlistitem, not contentdetails. in fact, snippet contains resourceid, in turn has videoid, ignore contentdetails anyway , do:
var request = gapi.client.youtube.playlistitems.list({ part: 'snippet', maxresults: 50, playlistid: 'alyl4ky05133rtmhtulsaxkj_y6el9q0jh' });
(possibly using fields parameter select parts of snippet you're after).
if need video information in addition fields in snippet, you're correct you'll have make set of calls (in batches of 50). design decision. use cases playlist item requests never need more info in snippet, can cut down on sending whole bunch of data whole bunch of apps ignore it. require that, in use cases need data, calls have made, efficiency of entire system gets better (a utilitarian engineering choice).
Comments
Post a Comment