'Warning file_get_contents () failed to open stream: HTTP request failed! HTTP/1.0 402 Payment Required
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
Solution 1:[1]
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);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | xxx |