php - Youtube API v3返回的结果少于要求的结果

标签 php api youtube

我正在使用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/

相关文章:

php - 在 mysql 中查询日期什么都不返回?

php - 需要有关 REST API(网络服务)的帮助以进行 woocommerce 结帐

HTML5 History API 实际 URL 不存在

python-3.x - 检查视频是否有年龄限制

java - 如何使用java按计数从youtube播放列表中获取视频?

php_network_getaddresses : getaddrinfo failed: nodename nor servname provided, 或未知失败?

php - 为我的数据库 mysql 中的每一行调用 php 脚本

CLI 模式下的 PHP APC

javascript - 尝试使用需要身份验证的 API 使用 Google 脚本从 TDAmeritrade 提取股票报价信息

youtube - PHP Youtube API v3 播放列表项中缺少描述