如何使用YouTube V3 API获取所有电影(非视频)

时间:2012-12-28 19:56:10

标签: youtube-api

我想列出YouTube上可用的所有电影(即可通过// @outube.com/movies获得的电影)。我可以看到如何查询那些使用API​​ V2,但这有1000个响应的限制。

使用V3 api,我可以看到电影的类别为id 30,但我无法弄清楚如何获得这个类别的所有电影。唯一的类别查询似乎会搜索指南类别,这些类别不同。

有关如何获取此列表的任何线索?如果可以,请帮忙!

2 个答案:

答案 0 :(得分:4)

我相信您可以获取与电影相关的自动生成频道,并使用其ID获取与此频道相关的播放列表,最后获取此播放列表中的项目(视频..),这些视频必须是与所选频道的电影:

检索电影频道:

请求

https://www.googleapis.com/youtube/v3/search?part=snippet&q=movies&type=channel&key={YOUR_API_KEY}

部分回复

"items": [
  {
   "id": {
    "kind": "youtube#channel",
    "channelId": "UCczhp4wznQWonO7Pb8HQ2MQ"
   },
   "kind": "youtube#searchResult",
   "etag": "\"eTr3dHIt5_K9qdGtRKL-5XdpiQI/sQpwXP-0MUEZzOQx4F0yKj0eUR4\"",
   "snippet": {
    "publishedAt": "2005-12-15T03:07:36.000Z",
    "channelId": "UCczhp4wznQWonO7Pb8HQ2MQ",
    "title": "movies",
    "description": "YouTube Movies (United States).",
    "thumbnails": {
     "default": {
      "url": "http://i.ytimg.com/i/czhp4wznQWonO7Pb8HQ2MQ/1.jpg"
     },
     "medium": {
      "url": "http://i.ytimg.com/i/czhp4wznQWonO7Pb8HQ2MQ/mq1.jpg"
     },
     "high": {
      "url": "http://i.ytimg.com/i/czhp4wznQWonO7Pb8HQ2MQ/hq1.jpg"
     }
    }
   }
  },

e.g。获取“YouTube电影(美国)”频道中的电影列表

请求

https://www.googleapis.com/youtube/v3/playlists?part=snippet&channelId=UCczhp4wznQWonO7Pb8HQ2MQ&key={YOUR_API_KEY}

部分回应:

{

   "id": "PLjygWhZE6KY0Uhw12FsAc8raAClz0l71C",
   "kind": "youtube#playlist",
   "etag": "\"eTr3dHIt5_K9qdGtRKL-5XdpiQI/TWrkoCkmJvq14neCcutnApHMMgU\"",
   "snippet": {
    "publishedAt": "2012-12-06T20:11:40.000Z",
    "channelId": "UCczhp4wznQWonO7Pb8HQ2MQ",
    "title": "The Nicolas Cage Collection",
    "description": "From panicked fathers to spirits of vengeance, Nicolas Cage has done it all.",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/nHiy8SVZdpU/default.jpg"
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/nHiy8SVZdpU/mqdefault.jpg"
     },
     "high": {
      "url": "https://i.ytimg.com/vi/nHiy8SVZdpU/hqdefault.jpg"
     }
    }
   }
  },

从此播放列表中获取项目:

请求:

https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=PLjygWhZE6KY0Uhw12FsAc8raAClz0l71C&key={YOUR_API_KEY}

部分回应:

{
 "kind": "youtube#playlistItemListResponse",
 "etag": "\"eTr3dHIt5_K9qdGtRKL-5XdpiQI/KSlqEnNGq36l47_k9W3fd79KfYQ\"",
 "pageInfo": {
  "totalResults": 15,
  "resultsPerPage": 5
 },
 "nextPageToken": "CAUQAA",
 "items": [
  {

   "id": "PLcBtbpFAOApiV34TU797yEFAUZuwhFrvJya3MqlZWkGM",
   "kind": "youtube#playlistItem",
   "etag": "\"eTr3dHIt5_K9qdGtRKL-5XdpiQI/C_xTa48Xof7giXobSula2vWX43A\"",
   "snippet": {
    "publishedAt": "2012-12-06T20:12:49.000Z",
    "channelId": "UCczhp4wznQWonO7Pb8HQ2MQ",
    "title": "Stolen",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/nHiy8SVZdpU/default.jpg"
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/nHiy8SVZdpU/mqdefault.jpg"
     },
     "high": {
      "url": "https://i.ytimg.com/vi/nHiy8SVZdpU/hqdefault.jpg"
     }
    },
    "playlistId": "PLjygWhZE6KY0Uhw12FsAc8raAClz0l71C",
    "position": 0,
    "resourceId": {
     "kind": "youtube#video",
     "videoId": "nHiy8SVZdpU"
    }
   }
  },
  {

   "id": "PLcBtbpFAOApiV34TU797yED-1zeMCoMGVxtVgtX9ZdsQ",
   "kind": "youtube#playlistItem",
   "etag": "\"eTr3dHIt5_K9qdGtRKL-5XdpiQI/LgSyqtZkwJXv6-2ajW0g-FsgddQ\"",
   "snippet": {
    "publishedAt": "2012-12-06T20:19:26.000Z",
    "channelId": "UCczhp4wznQWonO7Pb8HQ2MQ",
    "title": "Trespass",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/J_7Zug6ouy4/default.jpg"
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/J_7Zug6ouy4/mqdefault.jpg"
     },
     "high": {
      "url": "https://i.ytimg.com/vi/J_7Zug6ouy4/hqdefault.jpg"
     }
    },
    "playlistId": "PLjygWhZE6KY0Uhw12FsAc8raAClz0l71C",
    "position": 1,
    "resourceId": {
     "kind": "youtube#video",
     "videoId": "J_7Zug6ouy4"
    }
   }
  },

以这种方式,您可以根据需要创建视频列表

答案 1 :(得分:1)

这是我目前的答案 - 仍在努力,所以我还没有接受它

我计算出电影的categoryId是30.然后我使用这个categoryId搜索视频,然后查询字符串“movie”(因为我需要放东西)。这提供了超过1000个结果,并且即使使用v3 api,Google也会将查询限制为1000个结果。

所以我需要对查询进行分区。我已经能够使用publishedBefore和publishedAfter执行此操作。请注意,这些是上传日期而非发布日期。

这给了我一个电影列表。

这是一个示例查询 https://www.googleapis.com/youtube/v3/search?nextPageToken=CDIQAA&publishedBefore=2010-02-01T00%3A00%3A00Z&maxResults=50&q=movie&videoCategoryId=30&part=id%2Csnippet&key=yourAPIKeyHere&type=video&publishedAfter=2010-01-01T00%3A00%3A00Z

获得电影ID后,我会查询各个电影ID

https://www.googleapis.com/youtube/v3/videos?part=snippet%2CcontentDetails&maxResults=50&id=O7cSKNevYQc%2CN84-SoboM6c%2C9K_WO3lqDSc%2CWTJP0Z-bknc%2CdF9hwjeRbGE%2CPnefvJ9T1N0%2CDuM6B4yKgTU%2C0tI8iP2f58I%2Cr4lNJEnY0FA%2COFnMrx6yEcA%2CmUZUAeqOmbg%2CDjq0tHK-KTo%2CkY44nxk0qjg%2CcLYkUR5MY14%2CTZpcfYOOEXA%2C-0jA9DMX8Qs%2C2TQDV1m4X2s%2CBh3Tye1OQvk%2Ct5IwjMDVNz4%2CkOi88X6xeKg%2Ck53CuaAUtik%2CNaRuenqLb9g%2Cn9h-0Wgix7Q%2CQG8SiW2a_l0%2Cmk-D66Z1Ydg%2ClvmwofckpNc%2CgRQK4fTXfBM%2CPZHgLy48R3Q%2CwczeO0DVM0g%2CTpMDTG3dEYE%2C6JI8pN7BqEQ%2COv9yllk3hsY%2CsN09sfLPu0g%2CbfhLYJGN948%2CPiWusdK75Ys%2CeE5jh0YwTCY%2C_cIw3vr2Q18%2CSA4xg_k0aqI%2CUZdha0zTM6w%2CwUdkDSIBw94%2CAhR-LDSIOaI%2C1XMt40vJayU%2C83fPx5-aUL8%2CmJLjaKzu7PQ%2CZvj_zRGnwU0%2CtyIPMd7JXOA%2CToE10sC36KQ%2COVKXjOW6cD8%2CLPW1cXVjMrg&key=LALALA

我仍然需要通过查看结果中的以下json来过滤结果

  "contentDetails": {
    "duration": "PT1H35M14S",
    "regionRestriction": {
     "allowed": [
      "US"
     ]
    }

不幸的是,这仍然没有给我电影年或导演(这对于制作实际上是哪部电影很有用),或价格(你知道,人们觉得有趣)