如何在单个 API 调用中从多个 Youtube 频道获取最新视频 [英] How to get latest videos from multiple Youtube channels in single API Call
问题描述
我正在使用以下 PHP 代码从用户频道获取最新视频,
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);
有什么方法可以调用 Youtube API 并在单个 API 调用中获取来自不同用户频道的视频.并在页面上按降序列出视频.
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.
首先通过json格式调用api获取上传的视频总数:
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
使用:
$json = json_decode($jsonString);
print($json->data->totalItems . "\n");
得到viewcount,然后你可以计算剩下的!
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.
注意:XML 比 json 慢很多,我强烈建议您使用 json 格式!
这篇关于如何在单个 API 调用中从多个 Youtube 频道获取最新视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!