即使指定了type=video,YouTube Data API v3仍会返回youtube#channel结果
我正在使用YouTube Data API v3 search 端点,并且明确使用 type=video 对视频进行过滤,但仍然会收到结果,其中 id.kind 是 youtube#channel:
请求:
curl \
'https://youtube.googleapis.com/youtube/v3/search?part=snippet&q=rammstein&type=video&key=[YOUR_API_KEY]' \
--header 'Accept: application/json' \
--compressed
响应:
{
"kind": "youtube#searchListResponse",
"etag": "GNWT-T-iUAAVyeIhrHdqzjd-Sgg",
"nextPageToken": "CAUQAA",
"regionCode": "PL",
"pageInfo": {
"totalResults": 1000000,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "n4IGnrzGKO90iE07pCSbnUAOQkk",
"id": {
"kind": "youtube#channel",
"channelId": "UCYp3rk70ACGXQ4gFAiMr1SQ"
},
"snippet": {
"publishedAt": "2015-06-24T15:33:44Z",
"channelId": "UCYp3rk70ACGXQ4gFAiMr1SQ",
"title": "Rammstein Official",
"description": "The Official YouTube Channel #Rammstein Social Media: https://ramm.st/links RammsteinShop: https://shop.rammstein.de ...",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/ekNRsqZ4ziOZtWo0Re34VI0jpHx_Dkr7Xzx9EooZidgxCK0_OtysY-dDxUXq35S6qA0zjyPABiQ=s88-c-k-c0xffffffff-no-rj-mo"
},
"medium": {
"url": "https://yt3.ggpht.com/ekNRsqZ4ziOZtWo0Re34VI0jpHx_Dkr7Xzx9EooZidgxCK0_OtysY-dDxUXq35S6qA0zjyPABiQ=s240-c-k-c0xffffffff-no-rj-mo"
},
"high": {
"url": "https://yt3.ggpht.com/ekNRsqZ4ziOZtWo0Re34VI0jpHx_Dkr7Xzx9EooZidgxCK0_OtysY-dDxUXq35S6qA0zjyPABiQ=s800-c-k-c0xffffffff-no-rj-mo"
}
},
"channelTitle": "Rammstein Official",
"liveBroadcastContent": "none",
"publishTime": "2015-06-24T15:33:44Z"
}
},
{
"kind": "youtube#searchResult",
"etag": "eh_dnV_VSCXoRInALDa9E5fsuN4",
"id": {
"kind": "youtube#video",
"videoId": "NeQM1c-XCDc"
},
"snippet": {
"publishedAt": "2019-03-28T16:58:13Z",
"channelId": "UCYp3rk70ACGXQ4gFAiMr1SQ",
"title": "Rammstein - Deutschland (Official Video)",
"description": "Order the album: https://ramm.st/RammsteinAlbum ✚ Website: http://www.rammstein.com ✚ RammsteinShop: ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/NeQM1c-XCDc/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/NeQM1c-XCDc/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/NeQM1c-XCDc/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "Rammstein Official",
"liveBroadcastContent": "none",
"publishTime": "2019-03-28T16:58:13Z"
}
}
]
}
如你所见,第一项是一个频道,即使我指定了:type=video。文档明确写道: By default, a search result set identifies matching video, channel, and playlist resources, but you can also configure queries to only retrieve a specific type of resource.
问题
为什么API会返回 youtube#channel 结果,尽管 type=video 已被设置?
这是预期的行为,还是我的请求中有遗漏吗?
解决方案
考虑在请求中添加 videoType 参数。
示例:
curl \
'https://youtube.googleapis.com/youtube/v3/search?part=id,snippet&maxResults=50&q=rammstein®ionCode=PL&relevanceLanguage=PL&videoType=videoTypeUnspecified&key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--compressed
这里有一个可用的示例 可在YouTube API文档的try-it功能中使用。
有趣的是,我说不清楚具体原因,但它也会返回频道项,因此你必须在程序中排除这些结果。
再来一个示例:
curl \
'https://youtube.googleapis.com/youtube/v3/search?part=id,snippet&maxResults=50&q=rammstein®ionCode=PL&type=video&videoType=videoTypeUnspecified&key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--compressed
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。