Error accessing youtube api: 'Warning: file_get_contents () [function.file-get-contents]: URL> file access disabled ...'

I tried to answer this answer:

stack overflow

So, in my php document, I had the following variables:

$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'}; 

but this gave me an error:

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]: could not open the stream: no suitable shell can be found in /home/path/to/file.php on line 12

I looked at the developer guide here:

https://developers.google.com/youtube/2.0/developers_guide_php

and you can understand the feed and input structure here:

https://developers.google.com/youtube/2.0/developers_guide_protocol_understanding_video_feeds#Understanding_Video_Entries

and found several solutions (one of which is related to the twist), but they either did not work, or I did not know if they are the best method.

Can someone tell me if there is something wrong in the above code?

0
source share
2 answers

This is most likely because you do not have OpenSSL installed on your server. Try installing it, and if it still does not work, perhaps because you have HTTP access disabled in your php.ini (set allow_url_fopen to true)

+1
source

The best I've seen for this is Zend_GData_Youtube in the Zend Framework. It does not require anything special, but it is much simpler than a regular cURL or JSON request!

See there: http://framework.zend.com/downloads/latest

+1
source

Source: https://habr.com/ru/post/1444022/


All Articles