Youtube Data API v3 - Get video feeds of auto-generated channels

我的梦境 提交于 2019-12-02 22:01:27

问题


I want to use auto-generated channel Ids as example below...

GET https://www.googleapis.com/youtube/v3/channels?part=snippet&id=UCrfjym-5AEUY2QzXsddRIQA&fields=items(id%2Csnippet)&key={YOUR_API_KEY}

...to access their video contents. But seems I cannot make use of the part: 'snippet,contentDetails', or filter:'uploads' filtering method as I use for getting normal user channel Ids before grabbing their playlistItems. Is there a simple method to display video feed or playlist contents of an auto-generated channel? I use the gapi.client instead of the url. Thx for guidance.


回答1:


FINAL UPDATE:

Here is my solution for auto-generated Topic-based channel ids, since I'm using gapi.client, here's what works (relevant code only - URL samples below):

function requestUserUploadsPlaylistId(pageToken) {
var itemId = $("#YOUR-TEXT-INPUT").val(CHANNEL-ID); // Topic-based channel Id
var request = gapi.client.youtube.playlists.list({ // Use playlists.list
channelId: itemId, // Return the specified channel's playlist
part: 'snippet',
filter: 'items(id)' // This gets what you only need, the playlist Id
});
request.execute(function(response) {
playlistId = response.result.items[0].id;
requestVideoPlaylist(playlistId, pageToken); // Now call function to get videos
});
}

function requestVideoPlaylist(playlistId, pageToken) {
var requestOptions = {
playlistId: playlistId,
part: 'id,snippet',
maxResults: 6
};

var request = gapi.client.youtube.playlistItems.list(requestOptions);
request.execute(function(response) { // playlistItems.list is used here
. . .

Here's the URL sample of auto-generated Topic-based Id which grabs its playlist id: GET https://www.googleapis.com/youtube/v3/playlists?part=snippet&channelId=HC9m3exs6zk1U&fields=items%2Fid&key={YOUR_API_KEY} // Outputs sample playlist Id: LP9m3exs6zk1U

Now here's the URL sample using that playlist Id to get the videos from the auto-generated Topic-based channel Id: GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=5&playlistId=LP9m3exs6zk1U&key={YOUR_API_KEY} // Outputs video data you want.

Remember, Topic-based channel Ids come in different lengths, the above samples support current available lengths.

Hope This Helps!



来源:https://stackoverflow.com/questions/22596385/youtube-data-api-v3-get-video-feeds-of-auto-generated-channels

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!