本文介绍了为什么 Youtube V3 Data API 只返回该频道的 1 个视频结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:为什么我从以下使用 YouTube Data V3 API 执行的操作中只收到 1 个视频?我试图从 (https://www.youtube.com/user/JayLenosGarage/videos) 有多个视频.

Question: Why am I receiving only 1 video from the below actions I take with the YouTube Data V3 API? The example channel I am trying to pull videos from (https://www.youtube.com/user/JayLenosGarage/videos) has multiple videos.

我正在尝试从特定频道的 Youtube 数据 api v3 中获取所有视频及其相关 ID.让我们使用示例频道 JayLenosGarage.

I'm trying to fetch all the videos and their associated ids from the Youtube data api v3 for a specific channel. Let's use the example channel JayLenosGarage.

所以在 YouTube 上关注这个视频 (https://www.youtube.com/watch?v=jdqsiFw74Jk&t=757s) 说首先得到一个上传"通过查询频道#list api 获取id,然后使用上传id 通过播放列表#list api 运行查询,我通过API 资源管理器(我也尝试使用API​​_KEY 使用curl)为Youtube 上的JayLenosGarage 频道运行查询,如下所示并收到以下输出:

So following this video on YouTube (https://www.youtube.com/watch?v=jdqsiFw74Jk&t=757s) which says to first get an "uploads" id by querying the channels#list api, then taking using the uploads id to run a query thru playlists#list api, I ran queries thru the API explorer (I also tried curl with an API_KEY) for JayLenosGarage channel on Youtube as follows and received the following output:

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

播放列表#list 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": ""
    }
   }
  }
 ]
}

推荐答案

您必须调用 PlaylistItems 而不是 Playlist.我已将结果限制为 1 个结果,但您可以将 maxResults 设置为 50.

You have to call PlaylistItems instead of Playlist. I have limited the result to 1 result, but you can set maxResults to 50.

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/nbc\nFollow NBC: http://Twitter.com/NBC\nLike NBC: http://Facebook.com/NBC\nNBC Tumblr: http://NBCtv.tumblr.com/\nNBC Pinterest: http://Pinterest.com/NBCtv/\nNBC Google+: https://plus.google.com/+NBC\nNBC Instagram: http://instagram.com/nbctv\n\nRestoration Blog: November 2016 - Jay Leno's Garage\nhttps://youtu.be/A06akpknh_I\n\nJay Leno's Garage\nhttp://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 Quota,并且PlaylistItems#list 只需 1 个配额.

Of course you can use Search,too, but you have to keep in mind that calling Search costs 100 Quota, and PlaylistItems#list costs only 1 quota.

这篇关于为什么 Youtube V3 Data API 只返回该频道的 1 个视频结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 06:57