作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要为youtube iFrame实现自定义自动播放功能,因此我决定使用youtube api relatedToVideoId feature。
问题是,由于某种原因,当您尝试只获取1个相关视频时,即使它说结果很多,也根本不提供任何视频。
请求示例:
https://www.googleapis.com/youtube/v3/search?key=[YOUR_KEY]&maxResults=1&part=snippet&type=video&relatedToVideoId=DlFmfxACvig
响应:
{
"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。videoId
的
Google API Explorer example-在这里,我设置了带特定字段的请求。
{
"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。
关于youtube - Youtube api relatedToVideoId提供的视频数量不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54171559/
我是一名优秀的程序员,十分优秀!