问题:为什么我从YouTube Data V3 API采取的以下操作中只收到1个视频?我尝试从(https://www.youtube.com/user/JayLenosGarage/videos)中提取视频的示例频道有多个视频。
我正在尝试从Youtube数据api v3中获取特定频道的所有视频及其相关ID。让我们使用示例频道JayLenosGarage。
请关注YouTube上的视频(https://www.youtube.com/watch?v=jdqsiFw74Jk&t=757s),该视频首先通过查询频道#list api获取“上传”ID,然后使用上传ID通过播放列表运行查询#list api,我在Youtube上通过API浏览器(我也尝试使用带有API_KEY的卷曲)对Youtube上的JayLenosGarage频道进行了查询,并收到以下输出:
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"
}
}
}
]
}
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": ""
}
}
}
]
}
答案 0 :(得分:2)
要获取频道内所有视频的列表,请使用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
返回该频道内的所有视频。
希望它可以帮助你:)
答案 1 :(得分:0)
您必须致电PlaylistItems
而不是Playlist
。我将结果限制为1个结果,但您可以将maxResults设置为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个配额,而PlaylistItems#list
只需要1个配额。