我需要为youtube iFrame实现自定义自动播放功能,因此我决定使用youtube api relatedToVideoId feature。
问题在于,由于某种原因,当您尝试只获取1个相关视频时,即使它说结果很多,也根本不提供任何视频。
示例请求:
响应:
{
"kind": "youtube#searchListResponse",
"etag": "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/ShTuZSfQoay1YL6jgovx1wFiJSA\"",
"nextPageToken": "CAEQAA",
"regionCode": "KG",
"pageInfo": {
"totalResults": 553,
"resultsPerPage": 1
},
"items": []
}
如您所见,items
数组中没有视频,但它表示有553 totalResults
个视频。另外,如果您将maxResults
增加到2,则会获得1个视频。
答案 0 :(得分:0)
在测试了您在问题中提供的示例请求后,我做了以下修改:
maxResults
的值增加到2或更大。对于这种情况,我将值设置为5。
根据文档,值的范围在0到50之间。这是Google API Explorer example和您提供的videoId
-在那里,我设置了带特定字段的请求。
进行修改后,结果如下:
{
"pageInfo": {
"totalResults": 556,
"resultsPerPage": 5
},
"items": [
{
"id": {
"kind": "youtube#video",
"videoId": "WlosjSe5B8c"
},
"snippet": {
"channelId": "UCtylTUUVIGY_i5afsQYeBZA",
"title": "Lil Skies - Red Roses ft. Landon Cube (Dir. by @_ColeBennett_)",
"channelTitle": "Lyrical Lemonade"
}
},
{
"id": {
"kind": "youtube#video",
"videoId": "4eS5o3beHko"
},
"snippet": {
"channelId": "UCtylTUUVIGY_i5afsQYeBZA",
"title": "Lil Skies - Creeping ft. Rich The Kid (Dir. by @_ColeBennett_)",
"channelTitle": "Lyrical Lemonade"
}
},
{
"id": {
"kind": "youtube#video",
"videoId": "mzB1VGEGcSU"
},
"snippet": {
"channelId": "UCtylTUUVIGY_i5afsQYeBZA",
"title": "Juice WRLD - Lucid Dreams (Dir. by @_ColeBennett_)",
"channelTitle": "Lyrical Lemonade"
}
},
{
"id": {
"kind": "youtube#video",
"videoId": "kxloC1MKTpg"
},
"snippet": {
"channelId": "UCrFB54bqp8sda4udJyNswlA",
"title": "DJ Khaled - No Brainer (Official Video) ft. Justin Bieber, Chance the Rapper, Quavo",
"channelTitle": "DJKhaledVEVO"
}
}
]
}
尽管响应显示pageInfo.totalResults
为556,但YouTube具有自己的阈值,因此,我不相信在同一响应中获得这些数据量。我相信的上限是50。