如何验证谷歌视频代码?

时间:2011-02-09 12:33:00

标签: php api

在我的项目中,用户将Google视频代码插入文本框 - 我想证明所引用的视频确实存在。我目前正在使用YouTube API执行类似于YouTube参考的内容,但我不确定使用Google视频的最佳方法是什么。任何方向都会受到赞赏。

1 个答案:

答案 0 :(得分:1)

您是否可以请求该网址并查看该网址是否为404?

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;
}

以上网址仅供参考 - 使其适应。此外,如果您对此更加满意,可以使用cURL。