0

I was trying to follow this answer:

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

So in my php document I had the variables below:

$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 that gave me the 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]: failed to open stream: no suitable wrapper could be found in /home/path/to/file.php on line 12

I have looked at the developers guide here:

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

and can understand the feed and entry structure here:

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

and have found a few solutions (one involving curl) but they either haven't worked or I haven't known if they were the best method to use.

Can anyone please tell me if there is anything wrong in the above code?

Community
  • 1
  • 1
user1063287
  • 10,265
  • 25
  • 122
  • 218
  • 1
    check allow_url_fopen is ON or OFF in php.ini – GBD Nov 04 '12 at 13:42
  • 1
    http://stackoverflow.com/questions/6551379/file-get-contents-error check this out. If this might answer your query. – Sushant Gupta Nov 04 '12 at 13:43
  • 1
    You can also try using cURL allows you to retrieve data to. – Jonathan Römer Nov 04 '12 at 13:43
  • thank you all, host enabled allow_url_fopen and openssl and that error message went away, i have another one now but i think that is a coding issue `Catchable fatal error: Object of class stdClass could not be converted to string`. so more homework to be done, thank you again! – user1063287 Nov 04 '12 at 14:32

2 Answers2

1

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

narruc
  • 350
  • 4
  • 9
1

The best thing I saw for that is the Zend_GData_Youtube in the Zend Framework. It doesn't require anything special but it's much easier than a normal cURL or JSON request!

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

Frederick Marcoux
  • 2,195
  • 1
  • 26
  • 57
  • thank you for your information, i'm not familiar with zend yet, but i'm sure this tip will be helpful to someone, thank you! – user1063287 Nov 04 '12 at 14:33