-4

I want get in my site this text info:

http://gdata.youtube.com/feeds/api/videos/IyBvgi4ZlbM

when the video is not found.

how i can writte the code?

i don't understand here:

https://developers.google.com/youtube/2.0/developers_guide_php?csw=1

thank you!

  • I got the response http://gdata.youtube.com/feeds/api/videos/0KSOMA3QBU0. Your video id is invalid http://www.youtube.com/watch?v=IyBvgi4ZlbM – Bora Jul 05 '14 at 11:45
  • yes is invalid... i whant this text "Video not found" to see abrove all invalid video in my site. – user3806434 Jul 05 '14 at 12:01
  • possible duplicate of [How do I check if a video exists on YouTube, using PHP?](http://stackoverflow.com/questions/1383073/how-do-i-check-if-a-video-exists-on-youtube-using-php) –  Jul 05 '14 at 12:25

2 Answers2

0

Try this ;)

<?php
$headers = get_headers('http://gdata.youtube.com/feeds/api/videos/IyBvgi4ZlbM');
$is_ok = substr($headers[0], 9, 3) == 200;

if($is_ok){
    echo 'Video is OK :)';
}
else{
    echo 'Something is wrong :(';
}
Zemistr
  • 1,049
  • 7
  • 10
0

You can try checking the video is available or not with headers:

$headers = get_headers("http://gdata.youtube.com/feeds/api/videos/".$row['youtube']);

if (!strpos($headers[0], '200')) 
{
    echo "Video is not found";
}
Bora
  • 10,529
  • 5
  • 43
  • 73
  • good... new i need add this but got error " $headers = get_headers('http://gdata.youtube.com/feeds/api/videos/' echo $row['youtube'];?>'); " – user3806434 Jul 05 '14 at 12:19
  • got... Warning: get_headers(): This function may only be used against URLs in /home/swapes/domains/swapes.com/public_html/cppx/page_youtube.php on line 125 Video is not found – user3806434 Jul 05 '14 at 12:24
  • You missed `http://` :) Try this line `$headers = get_headers("http://gdata.youtube.com/feeds/api/videos/".$row['youtube']);` – Bora Jul 05 '14 at 12:27