gpt4 book ai didi

youtube - 使用YouTube API v3,我如何获得内容的持续时间和类型?通过搜索或获取详细信息

转载 作者:行者123 更新时间:2023-12-03 06:23:37 26 4
gpt4 key购买 nike

我试图用这个:

https://www.googleapis.com/youtube/v3/playlistItems?part=snippet,contentDetails&{playlist_id}&key={key}&maxResults=50


https://www.googleapis.com/youtube/v3/search?part=snippet&q=YouTube+Data+API&type=video&videoCaption=closedCaption&key={key}&maxResults=50

它说在文档中它是contentDetails.duration,但似乎在我收到的数据中没有。

最佳答案

为了获取有关播放列表中视频的详细信息,您需要为该播放列表中的每个视频使用snippetcontentDetailspart值,为每个视频点击Videos.list方法:

请求:

HTTP GET https://www.googleapis.com/youtube/v3/videos?part=snippet%2C+contentDetails&id=AKiiekaEHhI&key={YOUR_API_KEY}

响应(对于 id=AKiiekaEHhI):
{
"kind": "youtube#videoListResponse",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/Qz22l3E04nR4kuY2SGE5M_d1BMM\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{

"kind": "youtube#video",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/8X_byN22HJTh5FJyoMH9bFGR_Og\"",
"id": "AKiiekaEHhI",
"snippet": {
"publishedAt": "2015-05-04T10:01:43.000Z",
"channelId": "UCkvdZX3SVgfDW8ghtP1L2Ug",
"title": "The Legend of Zelda: Majora's Mask With Glitches - Part 17: Going Against the Flow",
"description": "Follow me on Twitter! http://twitter.com/swordlesslink\n\nFollow me on TwitchTV for live video game streaming! http://twitch.tv/swordlesslink",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/AKiiekaEHhI/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/AKiiekaEHhI/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/AKiiekaEHhI/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/AKiiekaEHhI/sddefault.jpg",
"width": 640,
"height": 480
}
},
"channelTitle": "Swordless Link",
"categoryId": "20",
"liveBroadcastContent": "none",
"localized": {
"title": "The Legend of Zelda: Majora's Mask With Glitches - Part 17: Going Against the Flow",
"description": "Follow me on Twitter! http://twitter.com/swordlesslink\n\nFollow me on TwitchTV for live video game streaming! http://twitch.tv/swordlesslink"
}
},
"contentDetails": {
"duration": "PT17M30S",
"dimension": "2d",
"definition": "hd",
"caption": "false",
"licensedContent": true
}
}
]
}

内容的持续时间可以在 duration字典中找到作为 contentDetails键的对象。
categoryId映射到您的视频类别,您必须使用 VideoCategories.list方法进行查找。

请求:
HTTP GET https://www.googleapis.com/youtube/v3/videoCategories?part=snippet&id={CATEGORY_ID}&key={YOUR_API_KEY}

响应(对于 id=20:
{
"kind": "youtube#videoCategoryListResponse",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/cVclmqPmb6Xbwij8SctXRUrSVhw\"",
"items": [
{
"kind": "youtube#videoCategory",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/WmA0qYEfjWsAoyJFSw2zinhn2wM\"",
"id": "20",
"snippet": {
"channelId": "UCBR8-60-B28hp2BmDPdntcQ",
"title": "Gaming",
"assignable": true
}
}
]
}
title字典中的 snippet键的对象返回所需视频类别的String值。

关于youtube - 使用YouTube API v3,我如何获得内容的持续时间和类型?通过搜索或获取详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30301704/

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