为什么Youtube V3数据API只返回这个频道的1个视频结果?



问题:为什么我只收到一个视频从下面的行动,我采取与YouTube数据V3 API?我试图从(https://www.youtube.com/user/JayLenosGarage/videos)中提取视频的示例频道有多个视频。

我试图从Youtube数据api v3中获取所有视频及其相关id,用于特定频道。让我们使用示例通道JayLenosGarage。

按照YouTube (https://www.youtube.com/watch?v=jdqsiFw74Jk&t=757s)上的这个视频,首先获取"uploads"id通过查询channels#list api,然后使用uploads id通过playlists#list api运行查询,我通过api资源管理器(我还尝试使用API_KEY curl)对Youtube上的JayLenosGarage频道运行查询,如下所示,并收到以下输出:

Channels#list api query:

GET https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id=UCQMELFlXQL38KPm8kM-4Adg&key=<API_KEY>
# returns: 
{
 "kind": "youtube#channelListResponse",
 "etag": ""sZ5p5Mo8dPpfIzLYQBF8QIQJym0/z48ndyqvca6Iiuq8GhSM74uM6Ho"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {
   "kind": "youtube#channel",
   "etag": ""sZ5p5Mo8dPpfIzLYQBF8QIQJym0/ZrtYB2hQFGE9E0BKmRhauZQb1kI"",
   "id": "UCQMELFlXQL38KPm8kM-4Adg",
   "contentDetails": {
    "relatedPlaylists": {
     "likes": "LLQMELFlXQL38KPm8kM-4Adg",
     "uploads": "UUQMELFlXQL38KPm8kM-4Adg",
     "watchHistory": "HL",
     "watchLater": "WL"
    }
   }
  }
 ]
}

播放列表#列表api查询:

GET https://www.googleapis.com/youtube/v3/playlists?part=snippet&id=UUQMELFlXQL38KPm8kM-4Adg&key=<API_KEY>
# returns: 
{
 "kind": "youtube#playlistListResponse",
 "etag": ""sZ5p5Mo8dPpfIzLYQBF8QIQJym0/DWOe-LD4_fSk0yC55HX_ZOrkuy4"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 20
 },
 "items": [
  {
   "kind": "youtube#playlist",
   "etag": ""sZ5p5Mo8dPpfIzLYQBF8QIQJym0/3CSCtGQNcyDVWQJAktkawoG7h7k"",
   "id": "UUQMELFlXQL38KPm8kM-4Adg",
   "snippet": {
    "publishedAt": "1970-01-01T00:00:00.000Z",
    "channelId": "UCQMELFlXQL38KPm8kM-4Adg",
    "title": "Uploads from Jay Leno's Garage",
    "description": "",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/hnjbaBzq7II/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/hnjbaBzq7II/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/hnjbaBzq7II/hqdefault.jpg",
      "width": 480,
      "height": 360
     },
     "standard": {
      "url": "https://i.ytimg.com/vi/hnjbaBzq7II/sddefault.jpg",
      "width": 640,
      "height": 480
     },
     "maxres": {
      "url": "https://i.ytimg.com/vi/hnjbaBzq7II/maxresdefault.jpg",
      "width": 1280,
      "height": 720
     }
    },
    "channelTitle": "Jay Leno's Garage",
    "localized": {
     "title": "Uploads from Jay Leno's Garage",
     "description": ""
    }
   }
  }
 ]
}

要获取频道内所有视频的列表,请使用Search: list方法。它将返回与API请求中指定的查询参数匹配的搜索结果集合。默认情况下,搜索结果集识别匹配的视频、频道和播放列表资源,但您也可以配置查询仅检索特定类型的资源。

下面是您需要执行的示例请求:

https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCQMELFlXQL38KPm8kM-4Adg&maxResults=50&key=YOUR_API_KEY

注意:您只能使用channel.list来获取那个频道的信息。它不会返回的列表里面有视频。因为你已经知道了它的通道ID通道,然后使用Search.list返回该频道内的所有视频。

希望对你有帮助

您必须呼叫PlaylistItems而不是Playlist。我将结果限制为1个结果,但您可以将maxResults设置为50。

PlaylistItems#list api query:

GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=UUQMELFlXQL38KPm8kM-4Adg&key=<API_KEY>
{
 "kind": "youtube#playlistItemListResponse",
 "etag": ""sZ5p5Mo8dPpfIzLYQBF8QIQJym0/cP-6KgbLq3nwDlAJIHbAFkoudaY"",
 "nextPageToken": "CAEQAA",
 "pageInfo": {
  "totalResults": 521,
  "resultsPerPage": 1
 },
 "items": [
  {
   "kind": "youtube#playlistItem",
   "etag": ""sZ5p5Mo8dPpfIzLYQBF8QIQJym0/ATGgNMMgOoMbS2iqcgFL9h4B3yI"",
   "id": "VVVRTUVMRmxYUUwzOEtQbThrTS00QWRnLkEwNmFrcGtuaF9J",
   "snippet": {
    "publishedAt": "2016-11-07T07:09:25.000Z",
    "channelId": "UCQMELFlXQL38KPm8kM-4Adg",
    "title": "Restoration Blog: November 2016 - Jay Leno's Garage",
    "description": "Jay gives an update on some of the restorations going on in the garage.n» Subscribe:  http://NBC.com/video/library/full-episodes/nNBC YouTube: http://www.youtube.com/nbcnFollow NBC: http://Twitter.com/NBCnLike NBC: http://Facebook.com/NBCnNBC Tumblr: http://NBCtv.tumblr.com/nNBC Pinterest: http://Pinterest.com/NBCtv/nNBC Google+: https://plus.google.com/+NBCnNBC Instagram: http://instagram.com/nbctvnnRestoration Blog: November 2016 - Jay Leno's Garagenhttps://youtu.be/A06akpknh_InnJay Leno's Garagenhttp://www.youtube.com/user/jaylenosgarage",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/A06akpknh_I/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/A06akpknh_I/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/A06akpknh_I/hqdefault.jpg",
      "width": 480,
      "height": 360
     },
     "standard": {
      "url": "https://i.ytimg.com/vi/A06akpknh_I/sddefault.jpg",
      "width": 640,
      "height": 480
     },
     "maxres": {
      "url": "https://i.ytimg.com/vi/A06akpknh_I/maxresdefault.jpg",
      "width": 1280,
      "height": 720
     }
    },
    "channelTitle": "Jay Leno's Garage",
    "playlistId": "UUQMELFlXQL38KPm8kM-4Adg",
    "position": 0,
    "resourceId": {
     "kind": "youtube#video",
     "videoId": "A06akpknh_I"
    }
   }
  }
 ]
}

当然您也可以使用Search,但是您必须记住调用Search需要花费100个配额,而PlaylistItems#list只需要花费1个配额。

相关内容

  • 没有找到相关文章

最新更新