我正在使用YouTube API请求一组将maxResults设置为50的视频,并且在返回的对象中,我得到以下信息:[totalResults] => 271 [resultsPerPage] =>50。一切正常,但仅该对象拥有3个视频。当我使用搜索结果更多的搜索字词时,它确实显示了更多内容,但仍未显示应显示的50个字词,仅当返回大量视频(例如1000+)时,我得到50个对象,这是怎么回事?
这是我的请求代码:
$searchResponse = $youtube->search->listSearch('id,snippet', array(
'q' => "Let's Play The Legend of Zelda",
'maxResults' => 50,
'type' => 'video',
'videoEmbeddable' => 'true',
'publishedAfter' => date("Y-m-d\TH:i:sP",strtotime('-2 days')),
'videoDuration' => 'short',
'videoDefinition' => 'high',
'order' => 'viewCount',
));
这是我返回的对象:
Array
(
...
[pageInfo] => Array
(
[totalResults] => 972
[resultsPerPage] => 50
)
[items] => Array
(
[0] => Array
...
[7] => Array
)
)
如您所见,它只能容纳8个视频,而它却有972个结果,应该给我50个。
最佳答案
这是YouTube API的问题。 totalResults
值可能返回不正确的数字,不应将其用于检查响应中有多少个结果。
问题-API成员回复
it's unfortunately a known issue, and in general, I would recommend treating totalResults as a very rough guide and ensure that you don't build any paging logic around it. The presence/absence of a nextPageToken in a response should be the only thing which indicates whether there are additional results available.
资料来源:https://code.google.com/p/gdata-issues/issues/detail?id=6125&can=1
在这种情况下,您可以做的是使用
count()
函数检查您有多少个物品。
关于php - Youtube API v3返回的结果少于要求的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22674174/