我正在尝试检索与“自动生成”youtube 频道相关的视频。
虽然它在一段时间前有效(至少在 2023 年), 最近我遇到了问题 -
channels
API 不再返回“流行”或“最近”等播放列表,只有“上传”。
但即使“上传”播放列表也没有有效的 playlistId —
playlistItems
API 抛出错误“找不到请求的 playlistId 参数标识的播放列表。”
这是示例代码:
const YT_KEY = ""; // put your google api key here
const YT_AUTO_CHANNEL_ID = "UCNXJk0T4LRLpWS5XlVSg4uQ";
fetch(`https://youtube.googleapis.com/youtube/v3/channels?part=contentDetails&id=${YT_AUTO_CHANNEL_ID}&key=${YT_KEY}`)
.then((response) => response.json())
.then((json) => {
console.log("Channel's related \"Uploads\" playlistId", json.items[0]?.contentDetails.relatedPlaylists.uploads);
if (json.items[0]?.contentDetails.relatedPlaylists.uploads) {
fetch(`https://youtube.googleapis.com/youtube/v3/playlistItems?part=id%2CcontentDetails%2Csnippet&playlistId=${json.items[0].contentDetails.relatedPlaylists.uploads}&maxResults=50&key=${YT_KEY}`)
.then((response) => response.json())
.then((json) => {
console.log("\"Uploads\" playlist videos response", json);
});
}
});
有什么办法可以解决这个问题?
YouTube Data API v3 再次不提供基本功能。
我建议您尝试我的开源基于网络抓取的YouTube操作API。事实上,通过获取 https://yt.lemnoslife.com/channels?part=popular,recent&id=CHANNEL_ID,您将在
item
中获得您正在寻找的视频。
UCNXJk0T4LRLpWS5XlVSg4uQ
,您将获得:
{
"kind": "youtube#channelListResponse",
"etag": "NotImplemented",
"items": [
{
"kind": "youtube#channel",
"etag": "NotImplemented",
"id": "UCNXJk0T4LRLpWS5XlVSg4uQ",
"nextPageToken": "4qmFsgL8AhIYVUNOWEprMFQ0TFJMcFdTNVhsVlNnNHVRGrACRWdaeVpXTmxiblFZQXlBQU1BRTRBZW9EeXdGSGNGVkNWMjlaUWtOdlRVSkRhWFExWkVZNWQxbFhaR3hZTTA1MVdWaENlbUZIT1RCWU1rNTJZbTVTYkdKdVVtWmtiVlo1WkVkc2FsbFhlSHBZTTBwc1dqSnNkbUp0Um5ORmFEa3pUbGMxUlZKdVRqRmxiVVkyVmxaR00xTXdUalpSVnpGRVZVaE9lVnB0Y0ZWWk1GWlZVa2hvY2tkcVRVRkJSMVoxUVVGR1IxVm5RVUpTYkVsQlFWRkNWbEV3TlZsVGJYTjNWa1JTVFZWcmVIZFdNVTB4VjBkNFYxVXlZekJrVmtWQlFWRkZRa0ZCUVVKQlFVRkNRVkZFZVRKeVQzRkRaMXBCUVVWbmVWVkVTUSUzRCUzRJoCLGJyb3dzZS1mZWVkVUNOWEprMFQ0TFJMcFdTNVhsVlNnNHVRcmVjZW50ODAx,Cgs0NTJ5cVNRNlpZMCj0z5C1BjIiCgJGUhIcEhgSFhMLFBUWFwwYGRobHB0eHw4PIBAREiEgTA%3D%3D",
"popular": [
{
"videoId": "zzNLHZ-PKW4",
"thumbnails": [
{
"url": "https:\/\/i.ytimg.com\/vi\/zzNLHZ-PKW4\/hqdefault.jpg?sqp=-oaymwE8CKgBEF5IWvKriqkDLwgBFQAAAAAYASUAAMhCPQCAokN4AfABAfgBtgiAAoAPigIMCAAQARhCIFAoZTAP&rs=AOn4CLAZVpCyE7i9nzWclrmE7UMZTHc4DA",
"width": 168,
"height": 94
},
...
],
"title": "Ranking DIAMOND CAMO in Every CALL OF DUTY",
"publishedAt": 1690930118,
"views": 3225420,
"channelTitle": "BOOM YT",
"channelId": "UCKnbXodUoiLVjTR1UGDpMHg",
"channelHandle": "@BoomTheGrinder",
"duration": 46,
"approval": "Verified"
},
...
],
"recent": [
{
"videoId": "Sissi8vHE-k",
"thumbnails": [
{
"url": "https:\/\/i.ytimg.com\/vi\/Sissi8vHE-k\/hqdefault.jpg?sqp=-oaymwEiCKgBEF5IWvKriqkDFQgBFQAAAAAYASUAAMhCPQCAokN4AQ==&rs=AOn4CLChI5dNVjrJmJxHSZF0hmR6eJwGHw",
"width": 168,
"height": 94
},
...
],
"title": "\u0628\u0631\u06cc\u0645 \u0628\u0631\u0627\u06cc 18k \u0634\u062f\u0646 \u0633\u0627\u0628 \u0647\u0627\u0645\u0648\u0646\u061f!Call of duty mobile with new iPad m4(:",
"publishedAt": 1721751745,
"views": 152898,
"channelTitle": "mehtiyt",
"channelId": "UCzpy5rDkscnvJd3ywklrPQA",
"channelHandle": "@mehtiyt",
"duration": 23239,
"approval": null
},
...
]
}
]
}