YouTube Search.list: big 'totalResults' property and no items in response

I'm a novice user of YouTube Data API. Am interested in the method Search.list and tried it as follows:

curl \
  'https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=50&publishedAfter=2020-01-01T00%3A00%3A00Z&publishedBefore=2020-01-01T00%3A01%3A00Z&q=Nemo&type=video&key=[YOUR_API_KEY]' \
  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \
  --compressed

The JSON response provided was:

{
  "kind": "youtube#searchListResponse",
  "etag": "r_b6korptu_RtbUGCZrdsQokN6M",
  "nextPageToken": "CDIQAA",
  "regionCode": "RU",
  "pageInfo": {
    "totalResults": 263644,
    "resultsPerPage": 50
  },
  "items": []
}

I'm wondering about how could the value of totalResults be 263644 when there are no items in the result set?

Is it possible that between the dates of 2020-01-01T00:00:00Z and 2020-01-01T00:01:00Z a number of 263644 videos related to the search key Nemo were published?

A similar question was asked on this forum, yet, upon years having passed, no answer emerged.

Upvotes: 0

Views: 189

Answers (1)

stvar
stvar

Reputation: 6965

First thing to acknowledge is that the property totalResults is not reliable by its very specification (the emphasis below is mine):

pageInfo.totalResults (integer)

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.

This peculiarity of totalResults was already mentioned within the question you quoted above and is also confirmed officially by Google's staff.

To confirm myself the statement emphasized above, I did call Search.list on your very same URL and obtained the following JSON response:

{
  "kind": "youtube#searchListResponse",
  "etag": "nR1UCL5Kru9VxHzZ2DnocjjIfjk",
  "nextPageToken": "CDIQAA",
  "regionCode": "...",
  "pageInfo": {
    "totalResults": 268418,
    "resultsPerPage": 50
  },
  "items": []
}

Moreover, repeating the same API call several times in a row (only seconds apart one from another), I never got the same value of totalResults, yet always got an empty items array.

There's only one thing to learn from here: between the two date-time values (2020-01-01T00:00:00Z and 2020-01-01T00:01:00Z), there's no video that matches the query term Nemo.

If only changing publishedBefore to 2020-01-01T01:00:00Z -- thus using the following URL:

https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=50&publishedAfter=2020-01-01T00%3A00%3A00Z&publishedBefore=2020-01-01T01%3A00%3A00Z&q=Nemo&type=video&key=...

for invoking the same endpoint --, the JSON response obtained contains an items array of only one element:

{
  "kind": "youtube#searchListResponse",
  "etag": "w5YKbVnLAwAFSmESM0ZoCCtvHo0",
  "nextPageToken": "CDIQAA",
  "regionCode": "...",
  "pageInfo": {
    "totalResults": 255015,
    "resultsPerPage": 50
  },
  "items": [
    {
      "kind": "youtube#searchResult",
      "etag": "qoMGew0LKTvIT7PdH6o7vJ8Ob9s",
      "id": {
        "kind": "youtube#video",
        "videoId": "YU2sbTlAxLk"
      },
      "snippet": {
        "publishedAt": "2020-01-01T00:33:51Z",
        "channelId": "UCgMTHBAZjC6mkq257UseEzQ",
        "title": "YANDA ZAKA NEMO NAMBOBIN WAYAR KA DA SU KA BACE",
        "description": "Ta yanda zaka nemo Lambobinka da suka Bace ================================== Ga link din da zaku shiga ...",
        "thumbnails": {
          ...
        },
        "channelTitle": "kk Techtube",
        "liveBroadcastContent": "none",
        "publishTime": "2020-01-01T00:33:51Z"
      }
    }
  ]
}

If publishedBefore is set to 2020-01-01T00:34:00Z, then the result set is identical with the one above.

These tests seem to indicate that Search.list works OK w.r.t. the issue you have risen.

Upvotes: 1

Related Questions