Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Videos missing from a channel's video list

I'm trying to retrieve information about all the videos of a given YouTube channel.

Here is my first request:

GET https://www.googleapis.com/youtube/v3/search?part=snippet&channelId={CHANNEL_ID}&maxResults=50&type=video&key={YOUR_API_KEY}

{
  "kind": "youtube#searchListResponse",
  "etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/15j9AlxbMtzBhzffpA04ahJgv9g\"",
  "nextPageToken": "CDIQAA",
  "regionCode": "FR",
  "pageInfo": {
    "totalResults": 375,
    "resultsPerPage": 50
  },
  "items": [
    "... 50 items here ..."
  ]
}

As you can see, there is a total of 375 results. So, using the nextPageToken, I search for the 50 next videos.

GET https://www.googleapis.com/youtube/v3/search?part=snippet&channelId={CHANNEL_ID}&maxResults=50&pageToken=CDIQAA&type=video&key={YOUR_API_KEY}

{
  "kind": "youtube#searchListResponse",
  "etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/7mmGfmqsGmfP8OggZWZVefQ7z6Q\"",
  "nextPageToken": "CGQQAA",
  "prevPageToken": "CDIQAQ",
  "regionCode": "FR",
  "pageInfo": {
    "totalResults": 375,
    "resultsPerPage": 50
  },
  "items": [
    "... 28 more items here ..."
  ]
}

There are only 28 items in this response. Furthermore, if I query for the next page:

GET https://www.googleapis.com/youtube/v3/search?part=snippet&channelId={CHANNEL_ID}&maxResults=50&pageToken=CGQQAA&type=video&key={YOUR_API_KEY}

This time, there are no items at all.

{
  "kind": "youtube#searchListResponse",
  "etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/XKJQFk8Z_J6XraQ0mVCRtVWnSYc\"",
  "nextPageToken": "CJYBEAA",
  "prevPageToken": "CGQQAQ",
  "regionCode": "FR",
  "pageInfo": {
    "totalResults": 375,
    "resultsPerPage": 50
  },
  "items": [
  ]
}

What causes this behavior? Is there something wrong with my request?

like image 413
Richard-Degenne Avatar asked Dec 05 '25 02:12

Richard-Degenne


1 Answers

In YouTube Data API v3 you should:

Step 1: get your channel's upload playlist

GET https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id=UCRVDPcrF_LTJo8u0bkzUL9A&key={YOUR_API_KEY}

json "kind": "youtube#channel", "etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/8HOHPc1ZO5cOiePp8nFHwKA99HM\"", "id": "UCRVDPcrF_LTJo8u0bkzUL9A", "contentDetails": { "relatedPlaylists": { "uploads": "UURVDPcrF_LTJo8u0bkzUL9A", "watchHistory": "HL", "watchLater": "WL" The uploads playlist for your channell is UURVDPcrF_LTJo8u0bkzUL9A

Step 2: use youtube.playlistItems.list to get all videos uploaded in yout channell by specifying the playlistId of your channel's uploads playlist

GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&pageToken={WHEN_YOU_HAVE_A_PAGETOKEN_PUT_IT_HERE}&playlistId=UURVDPcrF_LTJo8u0bkzUL9A&key={YOUR_API_KEY}


with reference to answers to questions:

  • youtube-api-v3-list-uploaded-videos
  • how-do-i-obtain-a-list-of-all-videos-in-a-channel-using-the-youtube-data-api-v3

about the behavior of Search: list API

as documented here: https://developers.google.com/youtube/v3/docs/search/list about search result property pageInfo.totalResultsI quote literally:

The total number of results in the result set.Please note that the value is an approximation and may not represent an exact value. In addition, the maximum value is 1,000,000.

You should not use this value to create pagination links. Instead, use the nextPageToken and prevPageToken property values to determine whether to show pagination links.

also, by some investigations I did testing it seems that the videos that are "missing" in the result, as you indicated, however, appear in the results when the optional parameter q is explicitly specified in the request, obviously only if the filter value specified can be satisfied by the data of the video in question.

like image 112
Franco Rondini Avatar answered Dec 09 '25 00:12

Franco Rondini