1

I'm trying to get the content of an external file (youtube json feed) I first tried using file_get_contents() and curl. None of them are giving me any response.

In php.ini allow_url_fopen is set to On. And I also tried turning off safe mode.

error_reporting('E_ALL');
ini_set('display_errors',1);
echo file_get_contents('http://gdata.youtube.com/feeds/api/playlists/760E7F6C9B5CD71E?v=2&alt=json');

What can be going wrong?

ilanco
  • 9,581
  • 4
  • 32
  • 37
cloetensbrecht
  • 203
  • 3
  • 5

1 Answers1

1

Use curl instead of file_get_contents. Something like this:

$url  = 'http://gdata.youtube.com/feeds/api/playlists/760E7F6C9B5CD71E?v=2&alt=json';
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
echo $data;
Michel Gokan Khan
  • 2,525
  • 3
  • 30
  • 54