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」返回日期,所以最新的出版物始終是第一......如果有人問津。

相關問題