我试着用这个:
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=50and
https://www.googleapis.com/youtube/v3/search?part=snippet&q=YouTube+Data+API&type=video&videoCaption=closedCaption&key={key}&maxResults=50It 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.
更多推荐
发布评论