【问题标题】:Youtube API v3 reading playlistYoutube API v3 阅读播放列表
【发布时间】:2015-08-18 23:08:47
【问题描述】:

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)",

我做错了什么,我有点迷茫。

【问题讨论】:

  • 你试过data.items[i].snippet.title吗?
  • 是的,我做到了,我得到了它的工作:-) 谢谢。我的问题有点快,我没有注意。

标签: java javascript ajax youtube youtube-api


【解决方案1】:

这样的事情会在 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);
        }
    });
});

【讨论】:

    猜你喜欢
    • 2016-09-17
    • 2021-03-24
    • 2014-07-02
    • 2018-06-11
    • 2017-06-25
    • 2013-12-02
    • 2015-04-23
    • 2017-11-01
    • 2013-09-20
    相关资源
    最近更新 更多