jQuery 2.1.0 | Youtube API 3 - Get uploaded channel videos

jQuery 2.1.0 | Youtube API 3 - Get uploaded channel videos

Migrating from Youtube API v2 to v3 is a genuine pain in the ass! In v3 there is more code to write in order to filter what you need to get. The worst of the bunch is attempting to access all videos that exist in a Youtube channel. Youtube API v3 recycles the code term "Playlist" to mean Playlist content AND Channel content, that itself is needlessly confusing, unlike v2 where everything coded was clearcut and intelligent. Anyhow,

I couldn't find practical sample on how to get the data needed to access uploaded Youtube channel content. I am trying this based on very broad application but hitting a wall somehow.

First yor're supposed to get the "playlist" ID of the channel ID...

  1. function GetPlaylistID() {
  2. gapi.client.setApiKey('Your-API-Key');
  3. gapi.client.load('youtube', 'v3', function(){
  4. var SelMenuOption = $("#Select-menu option:selected").val();
  5. var requestOptions = {
  6. mine: false, // False for public access?, no authorization needed.
  7. id: SelMenuOption,
  8. part: 'contentDetails'
  9. };
  10. request.execute(function(response) {
  11. var playlistId = response.result.channels[0].contentDetails.uploads;
    $('#SavedID').val(playlistId);
  12. });
  13. GetUploadedVideos();
  14. });
  15. }

..then you get the channel video uploads from the saved "playlist" ID mentioned above...

  1. function GetUploadedVideos() {
  2. gapi.client.setApiKey('Your-API-key');
  3. gapi.client.load('youtube', 'v3', function(){
  4. var savedID = $('#SavedID').val();
  5. var request = gapi.client.youtube.playlistItems.list({
  6. playlistId: savedID,
  7. part: 'snippet'
  8. });
  9.    
  10. request.execute(function(response) {
  11.   // Go through result.playlistItems to view list of uploaded videos?
  12.  
  13. for(var i=0;i<response.items.length;i++) {
  14. var rvideoID = response.playlistItems[i].id.videoId; // or snippet.videoId
  15. var rchannelID = response.playlistItems[i].snippet.channelId;
  16. var rchannelTitle = response.playlistItems[i].snippet.channelTitle
  17. var rTitle = response.playlistItems[i].snippet.title;
  18. var rDescription = response.playlistItemss[i].snippet.description;
  19. var rthumbnail = response.playlistItems[i].snippet.thumbnails.medium.url;
  20.  
  21. var ytresults = 'HTML ..."
  22. $('#printResult').append(ytresults);
  23. });
  24. )

These are the errors I get:

TypeError: response.result.channels is undefined (line 11 of GetPlaylistID)
TypeError: response.items is undefined (line 13 of GetUploadedVideos())

Any better solutions? Why so darn complicated??

dan