Php 检查Youtube视频是否有效?代码修复

Php 检查Youtube视频是否有效?代码修复,php,youtube,youtube-api,Php,Youtube,Youtube Api,我有一个数据库,里面有大约5000个视频,我注意到其中一些视频现在被删除了。。所以我决定写一个php脚本来修复批量检查。。 下面是我根据大多数答案实现的代码,但它没有给出正确的结果。它给出了一个403头的3/4的视频,虽然实际上超过90%的工作..我错过了什么吗 foreach ($video as $cat) { $str = explode("=",$cat->videourl); $headers = get_headers('http://gdata.y

我有一个数据库,里面有大约5000个视频,我注意到其中一些视频现在被删除了。。所以我决定写一个php脚本来修复批量检查。。 下面是我根据大多数答案实现的代码,但它没有给出正确的结果。它给出了一个403头的3/4的视频,虽然实际上超过90%的工作..我错过了什么吗

    foreach ($video as $cat) {  
    $str = explode("=",$cat->videourl);
    $headers = get_headers('http://gdata.youtube.com/feeds/api/videos/' . $str[1]);
    if (!strpos($headers[0], '200')) {
    print_r($headers[0].'<br>');
    $i=$i+1;
    print_r("Unpublish".$cat->id. PHP_EOL);
    }
    else{
 print_r("publish".$cat->id. PHP_EOL);
 }
    }
我在这里打印标题是为了调试它,对于大多数情况,HTTP/1.0 403是禁止的
编辑::我已经检查了VideoID是否正确传递,所以字符串处理没有问题

对于任何试图实现这一点的人,下面是代码。。非常感谢你的帮助,因为我花了很多时间让它为新的api工作

$headers = checkYoutubeId ($str[1]);
if ($headers == false) {
$i=$i+1;
$db->query('UPDATE `ckf_hdflv_upload` SET `published`="0" Where `id`='.$cat->id);
print_r("Unpublished".$cat->id. PHP_EOL);
}
else{
$db->query('UPDATE `ckf_hdflv_upload` SET `published`="1" Where `id`='.$cat->id);
}
}
}
echo('done'.$i);
function checkYoutubeId($id) {
if (!$data = @file_get_contents("http://gdata.youtube.com/feeds/api/videos/".$id)) return false;
if ($data == "Video not found") return false;
if ($data == "Private video") return false;
return true;
}