问题描述
使用适用于 Python 的 Google API 客户端库和搜索端点 API V3 执行以下查询:
Using the Google APIs Client Library for Python and the search endpoint API V3 did the follwing query:
search_response = youtube.search().list(
q="Mallorca",
part="id,snippet",
maxResults=50,
order="date",
publishedBefore="2014-1-1T2:00:00Z",
publishedAfter="2014-1-1T1:00:00Z",
).execute()
响应显示 search_response.pageInfo.totalResults
为 186.这意味着需要分页来检索所有结果.然而,在这个回复中,我在 search_response.items
下只得到一个结果(一个视频),而不是第一页的预期 50.
The response shows a search_response.pageInfo.totalResults
of 186. That means that paging is needed to retrieve all results. However in this response I get only one result (one video) under search_response.items
instead of the expected 50 of the first page.
如果我使用 nextPageToken
(=CDIQAA) 查询下一个结果页面:
If I use the nextPageToken
(=CDIQAA) to query for the next results page:
search_response = youtube.search().list(
q="Mallorca",
part="id,snippet",
maxResults=50,
order="date",
publishedBefore="2014-1-1T2:00:00Z",
publishedAfter="2014-1-1T1:00:00Z",
pageToken= "CDIQAA"
).execute()
我再次仅获得一个结果,即在第一次查询时检索到的相同视频(相同的 videoId
).当我浏览 search_response
的下一页直到没有更多页面可用(nextPageToken
未包含在响应中)时,也会发生同样的事情.
I obtain again only one result, the same video (same videoId
) retrieved at the first query. Same thing happens when I navigate through the next pages of the search_response
until no more pages are available (nextPageToken
not included in the response).
已阅读上一个问题:
还有这个:
是youtube数据吗如果您使用页面令牌,api 分页是否一致?(v3 数据 API)
但他们没有解释为什么我只得到一个结果,即响应提供的所有页面都使用相同的视频.
but they don't explain why I get only one result, the same video for all pages delivered by the response.
这是 youtube API 的问题还是我做错了什么?感谢您的帮助.
Is this an issue of the youtube API or I am doing something wrong? Thanks for your help.
推荐答案
这是 youtube API 的未解决问题:
This is an open issue for the youtube API:
预计很快会修复...
如果不应用排序,可以获得正确的结果.
The right results can be obtained if ordering is not applied.
这篇关于使用 youtube API V3 [Google APIs Client Library for Python] 分页时的意外行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!