0

我很困惑。最好的我可以告诉,我正在按照这封信的例子。也许我错过了一个参数,但我找不到它是什么。如何检索我的YouTube频道播放列表?

var request = gapi.client.youtube.channels.list({ 
    id: '<myId>', 
    part: 'contentDetails' 
}); 
request.execute(function(response) { 
    console.log(response); 
}); 

控制台响应没有项目,但我有3个播放列表作为公共。

[日志]对象(learndataapi.html,68行)

ETAG: “\” m2yskBQFythfE4irbTIeOgYYfBU/Rk41fm-2TD0VG1yv0-bkUvcBi9s \ “”

项目:[](0)

类型: “YouTube的#channelListResponse”

pageInfo:{使用totalResults:0,resultsPerPage:0}

RESU LT:{类型: “YOUTUBE#channelListResponse”,ETAG: “\” m2yskBQFythfE4irbTIeOgYYfBU/Rk41fm-2TD0VG1yv0-bkUvcBi9s \ “”,pageInfo:{使用totalResults:0,resultsPerPage:0},项:[]}

对象原型

任何线索?

回答

1

尝试此查询:

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/

更新:请尝试以下步骤:

  1. 使用查询

    https://www.googleapis.com/youtube/v3/channels?id={channel Id}key={API key}&part=contentDetails 
    
  2. 使用此 “上传” 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如果你不知道w如何获得频道ID,只需检查您想要的任何频道的页面源,然后搜索:data-channel-external-id并使用channelId参数的值。

你需要的另一件事是API KEY,确保你启用了你的Youtube API数据并使用你的API KEY作为关键参数。

如果您发送的HTTP请求时,你会得到的细节最多50 playlits,你有自己的ID访问也喜欢id:PLAC325451207E3105

+0

搜索工作到一个点。它带回了第一个播放列表和我所有的公开视频。它没有检索到其他两个播放列表。 我玩了gapi.client.youtube.channels.list,并意识到“ID”是指通道ID,而不是我的ID,但我仍然不明白为什么它没有返回所有播放列表的数组在我的频道上。我错过了一些重要的东西。 – CapnPamma

+0

您将收到带有视频ID和详细信息的JSON。您可以使用Results = 30来获得更多结果,我认为它可以返回多达50个视频。 –

+0

阅读本页:https://developers.google.com/youtube/v3/docs/search/list您可以使用pageToken获取更多结果 –

1

好了,终于响应,东西!我经历了很多选择,我不确定为什么它以前不是那么简单。猜猜我读过或读过别的东西。感谢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”返回日期,所以最新的出版物始终是第一......如果有人问津。

相关问题