【发布时间】:2012-10-24 12:23:30
【问题描述】:
我试图遵循这个答案:
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'};
但这给了我错误:
警告:file_get_contents() [function.file-get-contents]: URL 文件访问在服务器配置中被禁用 /home/path/to//file.php 在第 12 行
警告: file_get_contents(https://gdata.youtube.com/feeds/api/videos/xx-xxxxxxx?v=2&alt=json) [function.file-get-contents]:无法打开流:没有合适的 包装器可以在第 12 行的 /home/path/to/file.php 中找到
我在这里查看了开发人员指南:
https://developers.google.com/youtube/2.0/developers_guide_php
并且可以在这里了解提要和条目结构:
并找到了一些解决方案(一个涉及 curl),但它们要么没有工作,要么我不知道它们是否是最好的使用方法。
如果上面的代码有什么问题,谁能告诉我?
【问题讨论】:
-
检查 php.ini 中的 allow_url_fopen 是 ON 还是 OFF
-
stackoverflow.com/questions/6551379/file-get-contents-error 看看这个。如果这可能会回答您的问题。
-
您也可以尝试使用 cURL 允许您检索数据。
-
谢谢大家,主机启用了 allow_url_fopen 和 openssl 并且该错误消息消失了,我现在有另一个,但我认为这是一个编码问题
Catchable fatal error: Object of class stdClass could not be converted to string。所以还有更多的功课要做,再次感谢你!