Youtube关闭了api v2所以我必须重写一些脚本来阅读youtube播放列表..我已经设法用ajax读取播放列表中的项目。
for (var i in data.items)
但我似乎无法阅读视频的标题。 我试过了:
data.items[i].title
但似乎不起作用。
这是youtube数据的一部分。
"items": [
{
"kind": "youtube#playlistItem",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/nUoxGPc9-1QfJdGNICJpggBOQiw\"",
"id": "PL00i2_BlzsBvKHcdXdtJhomEFSeHrz4oI",
"snippet": {
"publishedAt": "2015-05-15T06:06:55.000Z",
"channelId": "UCKBfi2UItrlUlri-31wZTGA",
"title": "Patrick Rosa - Angels in the sky (Teaser)",
我做错了什么,我有点失落。
答案 0 :(得分:0)
这样的内容会为您提供JavaScript中特定播放列表中的所有标题:
gapi.client.setApiKey('{YOUR-API-KEY}');
gapi.client.load('youtube', 'v3', function () {
var request = gapi.client.youtube.playlistItems.list({
part: 'snippet',
playlistId: '{YOUR PLAYLIST ID}'
});
request.execute(function (response) {
for (var i = 0; i < response.items.length; i++) {
console.log(response.items[i].snippet.title);
}
});
});