gpt4 book ai didi

google-apps-script - 调用YOUTUBE视频API时无法获得视频时长

转载 作者:行者123 更新时间:2023-12-03 06:05:15 24 4
gpt4 key购买 nike

我调用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;
enter image description here
enter image description here

最佳答案

我认为在您的情况下,需要在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)})
引用:
  • Videos: list
  • 关于google-apps-script - 调用YOUTUBE视频API时无法获得视频时长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64761450/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com