如何检索我的 YouTube 频道播放列表?
How do I retrieve my YouTube channel playlists?
我很困惑。尽我所知,我正在严格按照示例进行操作。也许我缺少一个参数,但我找不到它是什么。
var request = gapi.client.youtube.channels.list({
id: '<myId>',
part: 'contentDetails'
});
request.execute(function(response) {
console.log(response);
});
控制台响应没有项目,但我有 3 个播放列表 public。
[Log] Object (learndataapi.html, line 68)
etag: "\"m2yskBQFythfE4irbTIeOgYYfBU/Rk41fm-2TD0VG1yv0-bkUvcBi9s\""
items: [] (0)
kind: "youtube#channelListResponse"
pageInfo: {totalResults: 0, resultsPerPage: 0}
result: {kind: "youtube#channelListResponse", etag: "\"m2yskBQFythfE4irbTIeOgYYfBU/Rk41fm-2TD0VG1yv0-bkUvcBi9s\"", pageInfo: {totalResults: 0, resultsPerPage: 0}, items: []}
Object Prototype
有什么线索吗?
试试这个查询:
https://www.googleapis.com/youtube/v3/search?key={your_key_here}&channelId={channel_id_here}&part=snippet,id&order=date&maxResults=30
点击这里了解更多信息:https://developers.google.com/youtube/v3/
更新:尝试以下步骤:
使用查询
https://www.googleapis.com/youtube/v3/channels?id={channel Id}key={API key}&part=contentDetails
使用此 "uploads" ID 查询 PlaylistItems 以获取视频列表,例如:
https://www.googleapis.com/youtube/v3/playlistItems?playlistId={"uploads" Id}&key={API key}&part=snippet&maxResults=50
新更新
对于播放列表,请执行以下操作:
function httpGet(theUrl)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
xmlHttp.send( null );
return xmlHttp.responseText;
}
var response = httpGet("https://content.googleapis.com/youtube/v3/playlists?channelId=UCCTVrRB5KpIiK6V2GGVsR1Q&maxResults=50&part=snippet&key=REPLACE-WITH-YOUR-API-KEY");
console.log(response);
因此在此代码中,您只需添加要检索播放列表的任何频道 ID,在这种情况下,我从具有此 ID 的频道检索:UCCTVrRB5KpIiK6V2GGVsR1Q
如果您不知道如何要获取频道 ID,只需检查您想要的任何频道的页面源并搜索此:data-channel-external-id
并使用 channelId 参数的值。
您需要的另一件事是 API KEY,确保您启用了 Youtube API 数据并使用 API KEY 作为关键参数。
如果您发送 http 请求,您将收到最多 50 个播放灯的详细信息响应,您还可以访问它们的 ID,例如 id:PLAC325451207E3105
嗯,终于!我已经经历了很多选择,我不确定为什么以前不这么简单。猜猜我过度阅读了某些东西。感谢 Emad 为我提供了 XMLHttpRequest,我可以从中构建 gapi 请求。
gapi.client.setApiKey(
apiKey
);
gapi.client.load('youtube', 'v3').then(function (){
gapi.client.youtube.playlists.list ({
channelId: '<channelId>',
maxResults: 50,
part: 'snippet'
}).then (function(response){
console.log(response.result);
},function(reason){
console.log(reason);
});
});
给出一个response.result:
[Log] Object (learndataapi.html, line 45)
etag: "\"m2yskBQFythfE4irbTIeOgYYfBU/Ax2NdOn2dk1o3kSplGj29Msov8Q\""
items: Array (2)
0 Object
etag: "\"m2yskBQFythfE4irbTIeOgYYfBU/qQMRAPjZkOKU3LcNUxjcSiBXu8k\""
id: "<playListId>"
kind: "youtube#playlist"
snippet: Object
channelId: "<channelId>"
channelTitle: "<channelTitle>"
description: "<channelDescription>"
localized: {title: "New playlist 2 with 2 videos", description: "This is new playlist 2 with 2 videos"}
publishedAt: "2017-05-08T22:47:16.000Z"
thumbnails: {default: {url: "https://i.ytimg.com/vi/GsNawgbVt18/default.jpg", width: 120, height: 90}, medium: {url: "https://i.ytimg.com/vi/GsNawgbVt18/mqdefault.jpg", width: 320, height: 180}, high: {url: "https://i.ytimg.com/vi/GsNawgbVt18/hqdefault.jpg", width: 480, height: 360}}
title: "New playlist 2 with 2 videos"
...
需要注意的一点:播放列表总是按 "publishedAt" 日期降序返回,所以最新的出版物总是排在第一位......如果有人关心的话。
我很困惑。尽我所知,我正在严格按照示例进行操作。也许我缺少一个参数,但我找不到它是什么。
var request = gapi.client.youtube.channels.list({
id: '<myId>',
part: 'contentDetails'
});
request.execute(function(response) {
console.log(response);
});
控制台响应没有项目,但我有 3 个播放列表 public。
[Log] Object (learndataapi.html, line 68)
etag: "\"m2yskBQFythfE4irbTIeOgYYfBU/Rk41fm-2TD0VG1yv0-bkUvcBi9s\""
items: [] (0)
kind: "youtube#channelListResponse"
pageInfo: {totalResults: 0, resultsPerPage: 0}
result: {kind: "youtube#channelListResponse", etag: "\"m2yskBQFythfE4irbTIeOgYYfBU/Rk41fm-2TD0VG1yv0-bkUvcBi9s\"", pageInfo: {totalResults: 0, resultsPerPage: 0}, items: []}
Object Prototype
有什么线索吗?
试试这个查询:
https://www.googleapis.com/youtube/v3/search?key={your_key_here}&channelId={channel_id_here}&part=snippet,id&order=date&maxResults=30
点击这里了解更多信息:https://developers.google.com/youtube/v3/
更新:尝试以下步骤:
使用查询
https://www.googleapis.com/youtube/v3/channels?id={channel Id}key={API key}&part=contentDetails
使用此 "uploads" ID 查询 PlaylistItems 以获取视频列表,例如:
https://www.googleapis.com/youtube/v3/playlistItems?playlistId={"uploads" Id}&key={API key}&part=snippet&maxResults=50
新更新
对于播放列表,请执行以下操作:
function httpGet(theUrl)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
xmlHttp.send( null );
return xmlHttp.responseText;
}
var response = httpGet("https://content.googleapis.com/youtube/v3/playlists?channelId=UCCTVrRB5KpIiK6V2GGVsR1Q&maxResults=50&part=snippet&key=REPLACE-WITH-YOUR-API-KEY");
console.log(response);
因此在此代码中,您只需添加要检索播放列表的任何频道 ID,在这种情况下,我从具有此 ID 的频道检索:UCCTVrRB5KpIiK6V2GGVsR1Q
如果您不知道如何要获取频道 ID,只需检查您想要的任何频道的页面源并搜索此:data-channel-external-id
并使用 channelId 参数的值。
您需要的另一件事是 API KEY,确保您启用了 Youtube API 数据并使用 API KEY 作为关键参数。
如果您发送 http 请求,您将收到最多 50 个播放灯的详细信息响应,您还可以访问它们的 ID,例如 id:PLAC325451207E3105
嗯,终于!我已经经历了很多选择,我不确定为什么以前不这么简单。猜猜我过度阅读了某些东西。感谢 Emad 为我提供了 XMLHttpRequest,我可以从中构建 gapi 请求。
gapi.client.setApiKey(
apiKey
);
gapi.client.load('youtube', 'v3').then(function (){
gapi.client.youtube.playlists.list ({
channelId: '<channelId>',
maxResults: 50,
part: 'snippet'
}).then (function(response){
console.log(response.result);
},function(reason){
console.log(reason);
});
});
给出一个response.result:
[Log] Object (learndataapi.html, line 45)
etag: "\"m2yskBQFythfE4irbTIeOgYYfBU/Ax2NdOn2dk1o3kSplGj29Msov8Q\""
items: Array (2)
0 Object
etag: "\"m2yskBQFythfE4irbTIeOgYYfBU/qQMRAPjZkOKU3LcNUxjcSiBXu8k\""
id: "<playListId>"
kind: "youtube#playlist"
snippet: Object
channelId: "<channelId>"
channelTitle: "<channelTitle>"
description: "<channelDescription>"
localized: {title: "New playlist 2 with 2 videos", description: "This is new playlist 2 with 2 videos"}
publishedAt: "2017-05-08T22:47:16.000Z"
thumbnails: {default: {url: "https://i.ytimg.com/vi/GsNawgbVt18/default.jpg", width: 120, height: 90}, medium: {url: "https://i.ytimg.com/vi/GsNawgbVt18/mqdefault.jpg", width: 320, height: 180}, high: {url: "https://i.ytimg.com/vi/GsNawgbVt18/hqdefault.jpg", width: 480, height: 360}}
title: "New playlist 2 with 2 videos"
...
需要注意的一点:播放列表总是按 "publishedAt" 日期降序返回,所以最新的出版物总是排在第一位......如果有人关心的话。