Am using the below PHP code to get the latest videos from a user channel,
$feedURL = 'http://gdata.youtube.com/feeds/api/users/USER-ID/uploads?max-results=50';
$sxml = simplexml_load_file($feedURL);
Is there any way I can call the Youtube API and get the videos from different user channels in the single API call. And list the videos in desc order on a page.
Sorry, you werent very clear on your answer.
First of get the total videos uploaded by calling the api with a json format:
http://gdata.youtube.com/feeds/api/users/LinusTechTips/uploads?v=2&alt=jsonc
use:
$json = json_decode($jsonString);
print($json->data->totalItems . "\n");
to get the viewcount, then you can calculate the rest!
$totalItems = $json->data->totalItems;
$maxResults = 50
$xmlResults = array();
for($i = $maxResults > $totalItems-50; $i+$maxResults) {
$xmlResults[] = simplexml_load_file(
'http://gdata.youtube.com/feeds/api/users/LinusTechTips/uploads?max-results=' . $i
);
}
To be clear; this is not tested. So im not sure it works; but this is the way to do it.
Note: XML is alot slower then json, I stronly advise you to use the json formatting!
You could try to set up a array with usernames/ids and foreach them. For example:
$usernames = array(
'xeonnnnn',
'LinusTechTips'
);
$xmlResults = null;
foreach ($usernames as $user) {
$xmlResults[] = simplexml_load_file(
'http://gdata.youtube.com/feeds/api/users/' . $user .'/uploads?max-results=50'
);
}