2011-02-09 66 views
0

在我的项目中,用户将Google视频代码插入文本框 - 我想证明所引用的视频确实存在。目前我正在使用YouTube API执行与YouTube参考相似的操作,但我不确定Google Video的最佳方法是什么。任何方向将不胜感激。如何验证谷歌视频代码?

回答

1

您可以请求URL并查看它是否404s?

function googleVideoExist($id) { 
    // Validate id however you need to 
    $id = (int) $id; 

    $headers = get_headers('http://video.google.com/videoplay?docid=' . $id, TRUE); 

    // get_headers() follows Location: headers, 
    // and they are all sent back in sequential order 
    foreach(array_reverse($headers) as $header => $value) { 
     if (strstr($value, '200')) { 
      return TRUE; 
     } 
    } 

    return FALSE; 
} 

上面的URL只是一个指南 - 适应它。另外,如果你对此更加适应,你可以使用cURL。

+0

我必须检查提供的谷歌视频代码是否存在? – Arung 2011-02-09 12:45:07