9
I’m needing to return all videos from a particular youtube user, but my current function only returns 50, which is the maximum allowed by the API. there is some method of doing this?
$cURL = curl_init(sprintf('http://gdata.youtube.com/feeds/api/users/%s/uploads?start-index=1&max-results=50&orderby=published', 'nerineitzke'));
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cURL, CURLOPT_FOLLOWLOCATION, true);
$return = curl_exec($cURL);
curl_close($cURL);
$xml = new SimpleXMLElement($return);
$i = 0;
foreach($xml->entry AS $video):
$titulo = (string)$video->title;
echo "$titulo <br/><br/>";
$i++;
endforeach;
echo $i; // i = 50
Yeah, I thought that too, but the problem is that there’s no return on the maximum number of videos, so how would you identify that the next loop contains videos, and whether it contains 50 or less?
– Rafael Alexandre
At the beginning of XML has a tag that says the total of results. Here:
<openSearch:totalResults>1128</openSearch:totalResults>
. You can base yourself on this value to make the calculation.– Michael Siegwarth
In any case, I recommend that you read in the documentation the part about "Pagination and total result Counts". The API does not guarantee that this number is accurate. In addition, there is a fixed limitation to the maximum number of videos that can be loaded (even paging).
– Michael Siegwarth
Ah, now I found out: there is a parameter in XML called
<link rel="next" />
. If it is present, it is a sign that there is another page. If it is not, you can stop the loop. Hugs– Michael Siegwarth