How do I use YouTube JavaScript API v3 so that I can get ALL channels as well as all playlists for a given user name, as JSON, etc?
I used following references
- https://developers.google.com/youtube/v3/docs/channels/list
- https://developers.google.com/youtube/v3/docs/playlists/list
https://stackoverflow.com/a/18767785/799593 does not seem to be working anymore.
Below is my code, calling the channel end-point. It basically performs HTTP GET operation using AngularJS, where "id" is the ChannelID, being passed by "query" parameter.
var getUrl = 'https://www.googleapis.com/youtube/v3/channels';
this.get = function (apiKey, query) {
var parameters = {
kind: 'youtube#channel',
part: 'contentDetails',
id: query,
maxResults: 3,
key: apiKey
}
return $http({
url: getUrl,
method: 'GET',
params: parameters
})
};
This query basically can only return the IDs for Uploaded Videos and Liked Videos for a given YouTube channel. Instead, I am looking to get a list of all Channels, for a given user.
I also tried following:
this.getByUserName = function (apiKey, query) {
var parameters = {
kind: 'youtube#channel',
part: 'contentDetails',
forUsername: query,
maxResults: 5,
key: apiKey
}
return $http({
url: getUrl,
method: 'GET',
params: parameters
})
};
But it only seem to return the "main channel", in other words, if I query with forUsername="Google", I get UCK8sQmJBp8GCxrOtXWBpyEA ... so in contradiction to my interpretation in the "mind-map" below, the correct hierarchy might be actually linking only one channel for each user account and such channel can have multiple playlists. But this actually does look confusing and over-thinked approach from Google/YouTube.
e.g. if user passes "Google" then the API would reply with all channels we see on https://www.youtube.com/user/Google/channels
This looked relatively straight forward but the API basically seem to be limited to a comma separated list of YouTube playlist IDs, but the question is how to get them in first place, given a UserID?
I am interested to get results equivalent to: https://www.youtube.com/user/UserID/playlists but following is what I have as of now.
var getUrl = 'https://www.googleapis.com/youtube/v3/playlists';
this.get = function (apiKey, query) {
var parameters = {
kind: 'youtube#playlist',
part: 'contentDetails',
id: query,
maxResults: 10,
pageToken: '',
key: apiKey
}
return $http({
url: getUrl,
method: 'GET',
params: parameters
})
};
I'd conclude my question with this "mind-map" of YouTube's hierarchy and with annotated example of Google with links. I am not sure if this is the correct representation, but I believe if I know the correct hierarchy it might give me a hint as to how to I get YouTube Channels and PlayLists for a given user using YouTube JavaScript API v3.
(Full size image at: http://i.imgur.com/GWoZvCE.png)