In my project, users insert a Google Video code into a textbox - I'd like to certify that the video being referenced does indeed exist. I'm presently using the YouTube开发者_开发知识库 API to do something similar with YouTube references, but I'm not sure what would be the best method with Google Video. Any direction would be appreciated.
Can you request the URL and see if it 404s or not?
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 above is a guide only - adapt it to suit. Also, you can use cURL if you are more comfortable with that.
精彩评论