2011-02-09 129 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