YouTube Search.list:大的“totalResults"属性并且没有响应项 [英] YouTube Search.list: big 'totalResults' property and no items in response
问题描述
我是 YouTube 数据 API 的新手用户.对 Search.list
方法很感兴趣,尝试如下:
curl \'https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=50&publishedAfter=2020-01-01T00%3A00%3A00Z&publishedBefore=2020-01-01T00%3A01%3A00=Nemo&type=video&key=[YOUR_API_KEY]' \--header '授权:持票人 [YOUR_ACCESS_TOKEN]' \--header '接受:应用程序/json' \--压缩
提供的 JSON 响应是:
<代码>{种类":youtube#searchListResponse",etag":r_b6korptu_RtbUGCZrdsQokN6M",nextPageToken":CDIQAA",区域代码":RU",页面信息":{总结果":263644,每页结果":50},项目":[]}
我想知道当结果集中没有项目时 totalResults
的值怎么会是 263644
?
在 2020-01-01T00:00:00Z
和 2020-01-01T00:01:00Z
的日期之间是否可能有多个 263644
个与搜索关键字Nemo
相关的视频被发布了?
一个类似的问题在这个论坛上被问到了,然而,经过多年过去了,没有答案.
首先要承认的是,属性 totalResults
的规范并不可靠(下面的重点是我的):><块引用>
结果集中的结果总数.请注意,该值是近似值,可能不代表准确值.此外,最大值为 1,000,000.
您不应使用此值来创建分页链接.而是使用 nextPageToken
和 prevPageToken
属性值来确定是否显示分页链接.
totalResults
的这种特殊性已经在您上面引用的问题和 也得到了 Google 工作人员的正式确认.
为了确认上面强调的声明,我确实在您的相同 URL 上调用了 Search.list
并获得了以下 JSON 响应:
<代码>{种类":youtube#searchListResponse",etag":nR1UCL5Kru9VxHzZ2DnocjjIfjk",nextPageToken":CDIQAA",区域代码":...",页面信息":{总结果":268418,每页结果":50},项目":[]}
此外,连续多次重复相同的 API 调用(彼此之间仅相隔几秒),我从来没有得到相同的 totalResults
值,但总是得到一个空的 items
数组.
这里只需要学习一件事:在两个日期时间值之间(2020-01-01T00:00:00Z
和 2020-01-01T00:01:00Z
),则没有与查询词 Nemo
匹配的视频.
如果仅将 publishedBefore
更改为 2020-01-01T01:00:00Z
-- 因此使用以下 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=...
为了调用同一个端点 --,得到的 JSON 响应包含一个只有一个元素的 items
数组:
<代码>{种类":youtube#searchListResponse",etag":w5YKbVnLAwAFSmESM0ZoCCtvHo0",nextPageToken":CDIQAA",区域代码":...",页面信息":{总结果":255015,每页结果":50},项目":[{种类":youtube#searchResult",etag":qoMGew0LKTvIT7PdH6o7vJ8Ob9s",身份证":{种类":youtube#video",videoId":YU2sbTlAxLk"},片段":{publishedAt":2020-01-01T00:33:51Z",channelId":UCgMTHBAZjC6mkq257UseEzQ",《标题》:《YANDA ZAKA NEMO NAMBOBIN WAYAR KA DA SU KA BACE》、《说明》:《Ta yanda zaka nemo Lambobinka da suka Bace ================================== 嘎link din da zaku shiga ...",缩略图":{...},频道标题":kk Techtube",liveBroadcastContent":无",发布时间":2020-01-01T00:33:51Z"}}]}
如果 publishedBefore
设置为 2020-01-01T00:34:00Z
,则结果集与上述相同.
这些测试似乎表明Search.list
可以正常工作.你提出的问题.
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.
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
andprevPageToken
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.
这篇关于YouTube Search.list:大的“totalResults"属性并且没有响应项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!