为什么Youtube V3 Data API只能为此频道返回1个视频结果?
问题:为什么我只能从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)后,首先通过查询频道列表api获取“上传”ID,然后使用上传ID运行查询通过播放列表#列表API,我运行查询通过API浏览器(我也尝试卷曲与API_KEY)JayLenosGarage频道在Youtube如下,并收到以下输出:
频道#列表api查询:
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": ""
}
}
}
]
}
要获取频道中所有视频的列表,请使用搜索:列表方法。 它将返回一组符合API请求中指定的查询参数的搜索结果。 默认情况下,搜索结果集标识匹配的视频,频道和播放列表资源,但您也可以将查询配置为仅检索特定类型的资源。
以下是您需要执行的示例请求:
https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCQMELFlXQL38KPm8kM-4Adg&maxResults=50&key=YOUR_API_KEY
注意:您只能使用channel.list
来获取该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个配额。
上一篇: Why is the Youtube V3 Data API only returning 1 video result for this channel?