首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >访问youtube api时出错:“警告: file_get_contents() [Function.file-get-content]:URL > file-access被禁用.”

访问youtube api时出错:“警告: file_get_contents() [Function.file-get-content]:URL > file-access被禁用.”
EN

Stack Overflow用户
提问于 2012-11-04 13:39:04
回答 2查看 2.3K关注 0票数 0

我试着跟着这个答案:

https://stackoverflow.com/a/3331372/1063287

因此,在我的php文档中,我有以下变量:

代码语言:javascript
复制
$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'};

但这给了我一个错误:

警告:在第12行/home/path/to//file.php中的服务器配置中禁用了file_get_contents()函数、文件-获取内容: URL文件访问 警告: file_get_contents(https://gdata.youtube.com/feeds/api/videos/xx-xxxxxxx?v=2&alt=json) Function.file-get内容:未能打开流:在第12行的/home/path/ to /file.php中找不到合适的包装器

我看过这里的开发人员指南:

php

并能理解这里的进料和入口结构:

Entries

并找到了一些解决方案(一个涉及卷曲),但它们要么没有起作用,要么我不知道它们是否是最好的使用方法。

有谁能告诉我上面的代码有什么问题吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-11-04 13:42:38

这很可能是因为服务器上没有安装OpenSSL。尝试安装它,如果它仍然不能工作,这可能是因为在您的php.ini中禁用了HTTP访问(将allow_url_fopen设置为true)。

票数 1
EN

Stack Overflow用户

发布于 2012-11-04 13:45:15

我看到的最好的事情就是Zend中的Zend_GData_Youtube。它不需要任何特殊的东西,但它比普通的cURL或JSON请求容易得多!

见:http://framework.zend.com/downloads/latest

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13219020

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档