php - how to check if a video id exists on youtube -
what trying check if video entered users exists or not , have searched lot , found : reretrieving_video_entry , looks deprecated, how possible using google apis client library php
check if video exists or not?
here's i'm using, works pretty well. youtube api v2. deprecated
$video = "ck3n2dc3fds"; $ch = curl_init(); curl_setopt($ch, curlopt_url, 'http://gdata.youtube.com/feeds/api/videos/'.$video); curl_setopt($ch, curlopt_header, 0); curl_setopt($ch, curlopt_returntransfer, 1); $content = curl_exec($ch); curl_close($ch); if ($content && $content !== "invalid id" && $content !== "no longer available") { $xml = new simplexmlelement($content); }else { //doesn't exist }
you can check if video exists using youtube data api (v3). download/clone api here.
and here's script made check if video exists given youtube video id.
require_once dirname(__file__).'/../google-api/src/google/autoload.php'; // or wherever autoload.php located $developer_key = 'yourkey'; $client = new google_client(); $client->setdeveloperkey($developer_key); // define object used make api requests. $youtube = new google_service_youtube($client); $video = "ck3n2dc3fds"; //youtube video id $searchresponse = $youtube->search->listsearch('id', array( 'q' => $video, //the search query, can name or anything, 'maxresults' => 1, //query result limit "type" => "video" )); $exists = false; foreach ($searchresponse['items'] $searchresult) { //if type video, "youtuve#video" if($searchresult['id']['kind'] == "youtube#video"){ if($video == $searchresult['id']['videoid']){ $exists = true; } } } if(!$exists){ echo "video not found"; }else echo "video found";
Comments
Post a Comment