youtube - Youtube apirelatedToVideoId 给出的视频数量不正确
问题描述
我需要为 youtube iFrame 实现自定义自动播放功能,所以我决定使用youtube api relatedToVideoId 功能。
问题是,由于某种原因,通常当您尝试仅获取 1 个相关视频时,它根本不会提供任何视频,即使它说结果中有很多视频。
示例请求:
回复:
{
"kind": "youtube#searchListResponse",
"etag": "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/ShTuZSfQoay1YL6jgovx1wFiJSA\"",
"nextPageToken": "CAEQAA",
"regionCode": "KG",
"pageInfo": {
"totalResults": 553,
"resultsPerPage": 1
},
"items": []
}
如您所见,items
数组中没有视频,但它说有 553 totalResults
。此外,如果您增加到maxResults
2,您将获得 1 个视频。
解决方案
在测试了您在问题中提供的示例请求后,我确实进行了以下修改:
- 将该
maxResults
值增加到 2 或更大。对于这种情况,我将值设置为 5。根据文档,值的范围在 0 到 50 之间。
这是您提供的Google API Explorer 示例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。
推荐阅读
- haskell - 为什么我的子函数调用次数呈指数级增长?
- python-asyncio - 如何决定是否增加 asyncio aiohttp 进程的数量?
- javascript - 在 google map api 中添加我们的 JSON 数据中心
- javascript - Express.js 将实时变量注入 HTML 文件?
- json - 提交时表单无法重定向到另一个页面 - ReactJS
- java - 如何让 PhoneNumberUtil 识别数组?
- r - 我想将下面表格的结果直接保存到 sqlserver 中的表中
- java - 在 JavaFX 中单击 RadioButton 时显示列表
- jquery - 删除存储在数组中的 Google 地图标记
- javascript - 如何在 Selenium JS 中获取子节点的数量