警告file_get_contents () 无法打开流:HTTP 请求失败!需要 HTTP/1.0 402 付款


Warning file_get_contents () failed to open stream: HTTP request failed! HTTP/1.0 402 Payment Required

我今天收到此错误,但在此之前,我的代码工作正常。

代码在本地主机上运行正常,但我的网站上出现错误

下面是产生错误的代码行:

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

和错误:

警告:file_get_contents(https://www.youtube.com/get_video_info?hl=en&video_id=SD3S27fMGzc&eurl=&el=detailpage&gl=US&ps=default):无法打开流:HTTP 请求失败!HTTP/1.0 402 需要付款 在/home/zyxs/public_html/site.com/vid/youtube 中.php2

试试这个

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);