我有一个PHP“foreach”脚本,用于从选定的YouTube频道中提取所有上传的视频(与每个相关数据)。然后,我可以选择我想要的视频。 现在我已经在YouTube论坛上提问过了,但他们不愿意在专门的api之外提供帮助。sxml feed中的php检查(如果存在节点)
到目前为止,我只有一个单一的YouTube频道,但为了我的网站的工作,我需要知道,所有渠道将工作。
对.....这是问题所在。 这就是我得到的。
警告:主()[function.main]:节点不再xxxxxxxx.php存在于管线24 警告:主()[function.main]:节点不再在上线xxxxxxxx.php存在24 致命错误:调用一个成员函数属性()非对象上在xxxxxxxx.php第27行
/////////////////// // PHP代码/////////////////////////
$thumb_count = 1;
if ($thumb_count <= 50){
$feedURL = 'http://gdata.youtube.com/feeds/api/users/' . $youtube . '/uploads?start-index=1&max-results=50';
// read feed into SimpleXML object
$sxml = simplexml_load_file($feedURL);
// iterate over entries in feed
foreach ($sxml->entry as $entry) {
// get nodes in media: namespace for media information
$media = $entry->children('http://search.yahoo.com/mrss/');
// get video player URL
$attrs = $media->group->player->attributes();
$watch = $attrs['url'];
// get video thumbnail
$attrs = $media->group->thumbnail[3]->attributes();
$thumbnail = $attrs['url'];
// get <yt:duration> node for video length
$yt = $media->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->duration->attributes();
$length = $attrs['seconds'];
// get <yt:stats> node for viewer statistics
$yt = $entry->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->statistics->attributes();
$viewCount = $attrs['viewCount'];
// get <gd:rating> node for video ratings
$gd = $entry->children('http://schemas.google.com/g/2005');
if ($gd->rating) {
$attrs = $gd->rating->attributes();
$rating = $attrs['average'];
} else {
$rating = 0;
}
$videoID = substr($watch, 31, 11);
$vidTitle = $media->group->title;
$channel = $entry->author->name;
$discript = $media->group->description;
$select .= '<table width="150" border="0">
<tr>
<td><div align="center"><font size="-1" >'.$media->group->title.'</font><br />
<div class="thumbnail"><a href="xxxxxx?id='.$videoID.'">
<img src="'.$thumbnail.'"width="120" height="90" /></a></div></div></td></tr>
</table><hr width="150" color="#FF0000" align="center" size="1" />';
++$thumb_count;
}
}
现在我试过了这个(以我有限的knowladge)
// get video player URL
$attrs = $media->group->player->attributes();
if (($attrs =='') || (!$attrs)) { //////no need to double up, but wanted to make sure
continue ;
}
这然后加载我的网页,但不正确,而且还给出了一个错误。
警告:主要()[function.main]:节点不再存在xxxxxxxx.php第21行
现在看到的,因为我需要通过foreach循环多次去,有几个节点要通过,我怎样才能检查,绕过并继续没有错误弹出?
埋葬的警告是不是一个解决方案,因为也有一个致命错误之后的警告。 – Shef
@Shef,偏离过程,但在他修正某些问题后(他的帖子的最后部分再次看到),其余的错误只是一个PHP警告,致命错误在他之前的代码中。所以我的回答是“继续没有出现错误”的特殊效果。 – toopay
@toopay,我把它放在我的脚本中,它似乎与我的“继续”功能一起工作。仍然需要研究它,看看我是否需要更多或其他的东西。谢谢。现在会做一些更多的测试,看看它是否打破.....;) – scrappy