使用YouTube API v3,我如何才能访问内容持续时间和流派?(With the YouTube API v3 how can I get access to content duration,

编程入门 行业动态 更新时间:2024-10-28 08:20:18
使用YouTube API v3,我如何才能访问内容持续时间和流派?(With the YouTube API v3 how can I get access to content duration, and genres? By search or get details)

我试着用这个:

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但这似乎并不存在于我收到的数据中。

I tried to use this:

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

and

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

It says in the documentation it is contentDetails.duration but this doesn't seem to be present in the data I receive.

最满意答案

要获取有关播放列表中视频的详细信息,您需要针对该播放列表中的每个视频点击Videos.list方法,其中包含以下part的snippet和contentDetails值:

请求:

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 } } ] }

可以在contentDetails字典中找到内容的持续时间作为duration键的对象。

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 } } ] }

snippet字典中title键的对象返回所需视频类别的字符串值。

In order to get the detailed information about a video in a playlist, you will need to hit the Videos.list method for every video in that playlist with the snippet and contentDetails values for part:

Request:

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

Response (for 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 } } ] }

The duration of the content can be found as the object for the duration key in the contentDetails dictionary.

The categoryId maps to your video category, which you will have to look up using the VideoCategories.list method.

Request:

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

Response (for 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 } } ] }

The object for the title key in the snippet dictionary returns the String value of the video category that you want.

更多推荐

本文发布于:2023-07-15 19:18:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1117784.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:流派   持续时间   内容   API   YouTube

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!