gpt4 book ai didi

youtube - Youtube api relatedToVideoId提供的视频数量不正确

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

我需要为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。
    根据文档,值的范围在0到50之间。

  • 这是带有您提供的 videoIdGoogle 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/

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