据我所知,您必须再次调用以检索此类详细信息(例如 duration) - 但这次,您需要 videoId 并制作拨打videos.list API。
因此,使用您在问题中添加的第一个调用(稍作修改),您将获得以下 URL:
请求 #1 - 搜索:
GET https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=5&q=lfc&fields=items(id%2FvideoId%2Csnippet%2Ftitle)%2CpageInfo&key={YOUR_API_KEY}
你可以test request #1 here。
第一个请求的结果(“搜索”请求)是:
{
"pageInfo": {
"totalResults": 1000000,
"resultsPerPage": 5
},
"items": [
{
"snippet": {
"title": "Liverpool FC"
}
},
{
"id": {
"videoId": "a0IrBTg6zcI"
},
"snippet": {
"title": "Bob Paisley: The Humble Genius | Liverpool's most successful manager in his own words"
}
},
{
"id": {
"videoId": "sxMbgeBreJ0"
},
"snippet": {
"title": "Inside Anfield: Liverpool 4-3 Crystal Palace | TUNNEL CAM from the Reds' dramatic win"
}
},
{
"id": {
"videoId": "g4TknSKYG98"
},
"snippet": {
"title": "1000 Premier League Goals at Anfield | Some of our favourite strikes"
}
},
{
"id": {
"videoId": "pMYCN506lXk"
},
"snippet": {
"title": "What Alex Oxlade-Chamberlain return REALLY means for Liverpool midfield? ● LFC News"
}
}
]
}
使用第一项videoIda0IrBTg6zcI,创建对videos.list API 的请求,如下所示。
请求 #2 - 视频:
GET https://www.googleapis.com/youtube/v3/videos?part=snippet%2C+contentDetails&id=a0IrBTg6zcI&fields=items(contentDetails%2Fduration%2Csnippet%2Ftitle%2Cstatistics%2Cstatus(embeddable%2CpublishAt))%2CpageInfo&key={YOUR_API_KEY}
你可以test the request #2 here。
第二个请求的结果(“视频”请求)是:
{
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"snippet": {
"title": "Bob Paisley: The Humble Genius | Liverpool's most successful manager in his own words"
},
"contentDetails": {
"duration": "PT1M47S"
}
}
]
}
您可以在“contentDetails”部分查看“duration”值。
您还可以尝试 YouTube 数据 API (v3) 参考文档中提供的 (try-it) 功能。
上面链接的 try-it 具有获取 videoId a0IrBTg6zcI 的视频信息的参数 - 此答案中使用的相同,但是,此请求包含您可能需要的更多数据。