我正在尝试遵循以下答案:
https://stackoverflow.com/a/3331372/1063287
因此,在我的php文档中,我具有以下变量:
$json = file_get_contents("https://gdata.youtube.com/feeds/api/videos/{$video_id}?v=2&alt=json");
$json_data = json_decode($json);
$video_title = $json_data->{'entry'}->{'title'};
$video_date = $json_data->{'entry'}->{'published'};
$video_duration = $json_data->{'entry'}->{'media:group'}->{'yt$duration'};
$video_views = $json_data->{'entry'}->{'yt$statistics'}->{'viewCount'};
$video_description = $json_data->{'entry'}->{'content'};
但这给了我错误:
Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /home/path/to//file.php on line 12
Warning: file_get_contents(https://gdata.youtube.com/feeds/api/videos/xx-xxxxxxx?v=2&alt=json) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /home/path/to/file.php on line 12
我在这里查看了开发人员指南:
https://developers.google.com/youtube/2.0/developers_guide_php
并可以在此处了解Feed和条目的结构:
https://developers.google.com/youtube/2.0/developers_guide_protocol_understanding_video_feeds#Understanding_Video_Entries
并找到了一些解决方案(其中一个涉及 curl ),但它们要么没有起作用,要么我不知道它们是否是最佳的使用方法。
有人可以告诉我上面的代码有什么问题吗?
最佳答案
这很可能是因为您的服务器上没有安装OpenSSL。尝试安装它,如果仍然不能使用,则可能是因为您在php.ini中禁用了HTTP访问(将allow_url_fopen设置为true)
关于php - 访问YouTube API时出错: 'Warning: file_get_contents() [function.file-get-contents]: URL > file-access is disabled…',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13219020/