0
votes

Question: Why am I receiving only 1 video from the below actions I take with the YouTube Data V3 API? The example channel I am trying to pull videos from (https://www.youtube.com/user/JayLenosGarage/videos) has multiple videos.

I'm trying to fetch all the videos and their associated ids from the Youtube data api v3 for a specific channel. Let's use the example channel JayLenosGarage.

So following this video on YouTube (https://www.youtube.com/watch?v=jdqsiFw74Jk&t=757s) which says to first get an "uploads" id by querying the channels#list api, then taking using the uploads id to run a query thru playlists#list api, I ran queries thru the API explorer (I also tried curl with an API_KEY) for JayLenosGarage channel on Youtube as follows and received the following output:

Channels#list api query:

GET https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id=UCQMELFlXQL38KPm8kM-4Adg&key=<API_KEY>
# returns: 
{
 "kind": "youtube#channelListResponse",
 "etag": "\"sZ5p5Mo8dPpfIzLYQBF8QIQJym0/z48ndyqvca6Iiuq8GhSM74uM6Ho\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {
   "kind": "youtube#channel",
   "etag": "\"sZ5p5Mo8dPpfIzLYQBF8QIQJym0/ZrtYB2hQFGE9E0BKmRhauZQb1kI\"",
   "id": "UCQMELFlXQL38KPm8kM-4Adg",
   "contentDetails": {
    "relatedPlaylists": {
     "likes": "LLQMELFlXQL38KPm8kM-4Adg",
     "uploads": "UUQMELFlXQL38KPm8kM-4Adg",
     "watchHistory": "HL",
     "watchLater": "WL"
    }
   }
  }
 ]
}

Playlist#list api query:

GET https://www.googleapis.com/youtube/v3/playlists?part=snippet&id=UUQMELFlXQL38KPm8kM-4Adg&key=<API_KEY>
# returns: 
{
 "kind": "youtube#playlistListResponse",
 "etag": "\"sZ5p5Mo8dPpfIzLYQBF8QIQJym0/DWOe-LD4_fSk0yC55HX_ZOrkuy4\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 20
 },
 "items": [
  {
   "kind": "youtube#playlist",
   "etag": "\"sZ5p5Mo8dPpfIzLYQBF8QIQJym0/3CSCtGQNcyDVWQJAktkawoG7h7k\"",
   "id": "UUQMELFlXQL38KPm8kM-4Adg",
   "snippet": {
    "publishedAt": "1970-01-01T00:00:00.000Z",
    "channelId": "UCQMELFlXQL38KPm8kM-4Adg",
    "title": "Uploads from Jay Leno's Garage",
    "description": "",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/hnjbaBzq7II/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/hnjbaBzq7II/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/hnjbaBzq7II/hqdefault.jpg",
      "width": 480,
      "height": 360
     },
     "standard": {
      "url": "https://i.ytimg.com/vi/hnjbaBzq7II/sddefault.jpg",
      "width": 640,
      "height": 480
     },
     "maxres": {
      "url": "https://i.ytimg.com/vi/hnjbaBzq7II/maxresdefault.jpg",
      "width": 1280,
      "height": 720
     }
    },
    "channelTitle": "Jay Leno's Garage",
    "localized": {
     "title": "Uploads from Jay Leno's Garage",
     "description": ""
    }
   }
  }
 ]
}
2

2 Answers

1
votes

To get the list of all videos inside a channel, use the Search: list method. It will return a collection of search results that match the query parameters specified in the API request. By default, a search result set identifies matching video, channel, and playlist resources, but you can also configure queries to only retrieve a specific type of resource.

Here is the sample request that you need to do:

https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCQMELFlXQL38KPm8kM-4Adg&maxResults=50&key=YOUR_API_KEY

NOTE: You will only use the channel.list to get the information of that channel. It will not return the list of videos inside it. Since you already know the channel ID of that channel, then use the Search.list to return all the videos inside of that channel.

Hope it helps you :)

1
votes

You have to call PlaylistItems instead of Playlist. I have limited the result to 1 result, but you can set maxResults to 50.

PlaylistItems#list api query:

GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=UUQMELFlXQL38KPm8kM-4Adg&key=<API_KEY>
{
 "kind": "youtube#playlistItemListResponse",
 "etag": "\"sZ5p5Mo8dPpfIzLYQBF8QIQJym0/cP-6KgbLq3nwDlAJIHbAFkoudaY\"",
 "nextPageToken": "CAEQAA",
 "pageInfo": {
  "totalResults": 521,
  "resultsPerPage": 1
 },
 "items": [
  {
   "kind": "youtube#playlistItem",
   "etag": "\"sZ5p5Mo8dPpfIzLYQBF8QIQJym0/ATGgNMMgOoMbS2iqcgFL9h4B3yI\"",
   "id": "VVVRTUVMRmxYUUwzOEtQbThrTS00QWRnLkEwNmFrcGtuaF9J",
   "snippet": {
    "publishedAt": "2016-11-07T07:09:25.000Z",
    "channelId": "UCQMELFlXQL38KPm8kM-4Adg",
    "title": "Restoration Blog: November 2016 - Jay Leno's Garage",
    "description": "Jay gives an update on some of the restorations going on in the garage.\n» Subscribe:  http://NBC.com/video/library/full-episodes/\nNBC YouTube: http://www.youtube.com/nbc\nFollow NBC: http://Twitter.com/NBC\nLike NBC: http://Facebook.com/NBC\nNBC Tumblr: http://NBCtv.tumblr.com/\nNBC Pinterest: http://Pinterest.com/NBCtv/\nNBC Google+: https://plus.google.com/+NBC\nNBC Instagram: http://instagram.com/nbctv\n\nRestoration Blog: November 2016 - Jay Leno's Garage\nhttps://youtu.be/A06akpknh_I\n\nJay Leno's Garage\nhttp://www.youtube.com/user/jaylenosgarage",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/A06akpknh_I/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/A06akpknh_I/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/A06akpknh_I/hqdefault.jpg",
      "width": 480,
      "height": 360
     },
     "standard": {
      "url": "https://i.ytimg.com/vi/A06akpknh_I/sddefault.jpg",
      "width": 640,
      "height": 480
     },
     "maxres": {
      "url": "https://i.ytimg.com/vi/A06akpknh_I/maxresdefault.jpg",
      "width": 1280,
      "height": 720
     }
    },
    "channelTitle": "Jay Leno's Garage",
    "playlistId": "UUQMELFlXQL38KPm8kM-4Adg",
    "position": 0,
    "resourceId": {
     "kind": "youtube#video",
     "videoId": "A06akpknh_I"
    }
   }
  }
 ]
}

Of course you can use Search,too, but you have to keep in mind that calling Search costs 100 Quota, and PlaylistItems#list costs only 1 quota.