3
votes

I got this error today but before that, my code was working fine.

The code is working fine on localhost but I get error on my website

Here is the line of code that produces the error:

$data = file_get_contents("https://www.youtube.com/get_video_info?hl=en&video_id={$_GET['id']}&eurl=&el=detailpage&gl=US&ps=default");

and the error:

Warning: file_get_contents(https://www.youtube.com/get_video_info?hl=en&video_id=SD3S27fMGzc&eurl=&el=detailpage&gl=US&ps=default): failed to open stream: HTTP request failed! HTTP/1.0 402 Payment Required in /home/zyxs/public_html/site.com/vid/youtube.php on line 2

1
Probably because your trying to download something you need to pay for? - André Ferraz
@Andre this code is working in my localhost but in my website its is showing error - user2468472
@watcher error is same but i did not understand how to fix it can you help me to fix this issue - user2468472
@user2468472 without going over the whole set of answers there, try this approach. If that fails, try rewording your question around trying to get that curl call to work. - Jeff Lambert

1 Answers

0
votes

Try this one

function http_get_contents($url)
{
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_TIMEOUT, 1);
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  if (FALSE === ($retval = curl_exec($ch))) {
    echo curl_error($ch);
  } else {
    return $retval;
  }
}

$request_url = 'http://gdata.youtube.com/feeds/api/videos/SD3S27fMGzc';
$result = http_get_contents($request_url);

$simpleXML = new SimpleXMLElement($result);

print_r($simpleXML);