我试图从新到旧的顺序从多个频道获取最新3个视频的ID。这是我正在使用的代码。
$latest_vid_id = NULL;
$username_id = array('djvlad', 'UCIMQYiLXCHQLZCfplSP1rMw','UCUsTSbCLD96-pcWi2Kqaitg');
foreach($username_id as $username) {
$xml = simplexml_load_file(sprintf('http://gdata.youtube.com/feeds/base/users/%s/uploads?alt=rss&v=2&orderby=published', $username));
if ( ! empty($xml->channel->item[0]->link) )
{
parse_str(parse_url($xml->channel->item[0]->link, PHP_URL_QUERY), $url_query);
if ( ! empty($url_query['v']) )
$latest_vid_id = $url_query['v'];
}
echo $latest_vid_id.'<br>';
}
这个问题是它从每个频道获取最新视频的ID,我需要所有频道中的最新视频。谢谢
答案 0 :(得分:0)
试试这个
<?php
$id = NULL;
$username = 'YouTube';
$xml = simplexml_load_file(sprintf('http://gdata.youtube.com/feeds/base/users/%s/uploads?alt=rss&v=2&orderby=published', $username));
if ( ! empty($xml->channel->item[0]->link) )
{
parse_str(parse_url($xml->channel->item[0]->link, PHP_URL_QUERY), $url_query);
if ( ! empty($url_query['v']) )
$id = $url_query['v'];
}
echo $id;