问题
I'm using the YouTube API to request a set of videos I have maxResults set to 50 and in the returned object I get the following information: [totalResults] => 271 [resultsPerPage] => 50. All fine, but the object only holds 3 videos. When I use a search term with more results it does show more but still not the 50 that it should, only when a lot of videos are returned (say 1000+) then I get 50 in the object, what is going on here?
Here's my request code:
$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',
));
And here is my returned object:
Array
(
...
[pageInfo] => Array
(
[totalResults] => 972
[resultsPerPage] => 50
)
[items] => Array
(
[0] => Array
...
[7] => Array
)
)
As you can see it only hold 8 videos while it has 972 results and should give me 50.
回答1:
This is an issue with YouTube API. The totalResults
value may returns not accurate numbers and it shouldn't be used to check how many results are in the response.
Issue - API Member reply
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.
Source: https://code.google.com/p/gdata-issues/issues/detail?id=6125&can=1
What can you do in this situation is to use count()
function to check how many items you've got.
来源:https://stackoverflow.com/questions/22674174/youtube-api-v3-returning-less-then-requested-results