使用YouTube API v3,我如何才能访问内容持续时间和流派?通过搜索或获取详细信息

时间:2015-05-18 11:13:38

标签: youtube youtube-api

我试着用这个:

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

2 个答案:

答案 0 :(得分:0)

如果您选中Ember docs,则会看到它不在该响应中。

这实际上是一个功能请求:search resource

您可以跟进该问题。

答案 1 :(得分:0)

要获取播放列表中视频的详细信息,您需要针对该播放列表中包含snippetcontentDetails值的每个视频点按Videos.list方法part

请求:

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键的对象返回所需视频类别的字符串值。