验证YouTube视频
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了验证YouTube视频相关的知识,希望对你有一定的参考价值。
This function validates the URL of a YouTube video. It supports four kinds of URL: ?v=, /v/, #!v=, and the short version (youtu.be).To validate the ID a request to YouTube is made, this is done using a personal class utilizing cURL.
public function isYoutubeVideo($value) { $isValid = false; //validate the url, see: http://snipplr.com/view/50618/ if (isValidURL($value)) { //code adapted from Moridin: http://snipplr.com/view/19232/ $idLength = 11; $idOffset = 3; if ($idStarts === FALSE) { } if ($idStarts === FALSE) { } if ($idStarts === FALSE) { $idOffset = 4; } if ($idStarts === FALSE) { $idOffset = 9; } if ($idStarts !== FALSE) { //there is a videoID present, now validate it $http = new HTTP("http://gdata.youtube.com"); $result = $http->doRequest("/feeds/api/videos/".$videoID, "GET"); //returns Array('headers' => Array(), 'body' => String); $code = $result['headers']['http_code']; //did the request return a http code of 2xx? $isValid = true; } } } return $isValid; }
以上是关于验证YouTube视频的主要内容,如果未能解决你的问题,请参考以下文章
Android YouTube Player API Fragment无法手动处理触摸事件