我调用YT搜索API,然后获取每个视频结果(视频API)的完整数据。
但是,我无法获得每个视频的时长。
我收到未定义的错误:
var videoResultsFullData = YouTube.Videos.list('id,snippet', { id : searchResults.map(item => item.id.videoId)})
var popularChannelIds = YouTube.Channels.list('id,snippet, statistics', {
id: resultsParentChannelIds
}).items.filter(ch => ch.statistics.subscriberCount > sh.getRange("D24").getValue() ).map(channel => channel.id);
// .filter(video => popularChannelIds.includes(item.id.channelId));
var videoPopularResultsFullData =
videoResultsFullData.getItems()
.filter(video => popularChannelIds.includes(video.snippet.channelId));
// };
var range = 3;
for (var i in videoPopularResultsFullData) {
var item = videoPopularResultsFullData[i];
var temp = item.getContentDetails().duration;
答案 0 :(得分:0)
我认为在您的情况下,必须在contentDetails
中加入part
。那么下面的修改如何?
var videoResultsFullData = YouTube.Videos.list('id,snippet', { id : searchResults.map(item => item.id.videoId)})
var videoResultsFullData = YouTube.Videos.list('id,snippet,contentDetails', { id : searchResults.map(item => item.id.videoId)})
或者,您也可以如下使用part
作为数组。
var videoResultsFullData = YouTube.Videos.list(["id","snippet","contentDetails"], { id : searchResults.map(item => item.id.videoId)})