Youtube API从频道获取每个播放列表及其包含的视频

时间:2016-08-11 10:06:49

标签: javascript jquery youtube youtube-api

我正在尝试创建Youtube播放列表和每个列表项的列表,以包含播放列表的视频。

这样的事情(这将是一个播放列表部分):

Playlist Section

我遇到的问题是在我requestVideoPlaylist renderPlaylistSection内调用undefined函数时requestVideoPlaylist。但是,如果我在playlistId函数之外使用给定render...调用// Retrieve the list of playlists function requestPlaylists(channelId) { playlistsContainer.html(''); var requestOptions = { channelId: channelId, part: 'snippet,contentDetails', maxResults: 4 } var request = gapi.client.youtube.playlists.list(requestOptions); request.execute(function(response) { var playlists = response.result.items; if (playlists) { $.each(playlists, function(index, item) { renderPlaylistSection(playlistsContainer, item.id, item.snippet); }); } else { playlistsContainer.html('Sorry, you have no uploaded videos'); } }); } // Retrieve the list of videos in the specified playlist. function requestVideoPlaylist(playlistId, pageToken) { var requestOptions = { playlistId: playlistId, part: 'snippet,contentDetails', maxResults: 5 }; if (pageToken) { requestOptions.pageToken = pageToken; } var request = gapi.client.youtube.playlistItems.list(requestOptions); request.execute(function(response) { // Only show pagination buttons if there is a pagination token for the // next or previous page of results. nextPageToken = response.result.nextPageToken; var nextVis = nextPageToken ? 'visible' : 'hidden'; $('.js-next-videos').css('visibility', nextVis); prevPageToken = response.result.prevPageToken var prevVis = prevPageToken ? 'visible' : 'hidden'; $('.js-prev-videos').css('visibility', prevVis); var playlistItems = response.result.items; if (playlistItems) { $.each(playlistItems, function(index, item) { if (this.snippet.thumbnails) { renderVideoItem(item.snippet); } }); } }); } // Render playlist section function renderPlaylistSection(container, playlistId, playlistSnippet) { var title = playlistSnippet.title; container.append( '<div class="playlist"><h3>Playlist Title: ' + title + '</h3>' + '<div class="row playlist-videos">' + requestVideoPlaylist(playlistId) + '</div></div>' ); } function renderVideoItem(videoSnippet) { var title = videoSnippet.title; var thumbnail = videoSnippet.thumbnails.medium.url; return ( '<div class="thumb" style="overflow: hidden;">' + '<img src="' + thumbnail + '">' + '</div>' ); } ,则会正确返回结果。

请在以下行中找到我的代码。

我还在JSFiddle

上进行了复制
job_000000_0000

0 个答案:

没有答案