Tuesday, August 17, 2010

How to get the totalResults from YouTube video API search

Following code will get the total number of results returned for a given search query, This will help you design custom pagination for the results.

$query = $yt->newVideoQuery();
$query->setOrderBy('updated');
$query->setSafeSearch('none');
$query->setVideoQuery('Test');
$query->setAuthor('GoogleDevelopers');
$query->setMaxResults(10);
$query->setStartIndex(1);
        
$videoFeed = $yt->getVideoFeed($query->getQueryUrl(2));

$all_results = $videoFeed->getTotalResults()->text;

No comments:

Post a Comment