php - 访问YouTube API时出错: 'Warning: file_get_contents() [function.file-get-contents]: URL > file-access is disabled…'

标签 php json video youtube

我正在尝试遵循以下答案:

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/

相关文章:

javascript - Apple/Safari 问题在移动设备上播放背景视频

PHP ONE 脚本处理所有请求

php - Laravel Eloquent 在哪里替换和比较

java - 从 Node.js 调用 Java Lambda 函数

java - 如何转换 JSON 中的部分字符串?

ios - 如何将视频转码为16 :9 format and vary the bit rate (and perhaps FPS)?

video - 如何连接具有不同属性的ffmpeg中的视频?

javascript - 如何让人们在同一表单上进行协作并实时更新?

php - 有没有办法通过 JavaScript 设置 php 变量

javascript - 如何将 Firebase 用作具有生成键(JS)的关系数据库?