1

I'm trying to get release data in JSON format via Discogs API, but it doesn't work. What am I doing wrong? This code works well with other URLs.

<?php 
$opts = array('http' => array('method' => 'GET',
'header' => 'Accept-Encoding: gzip,
deflate\r\nUser-Agent: TheVinylCrate/1.0 +http://www.hazadus.net\r\n')); 

$context = stream_context_create($opts); 

echo file_get_contents('http://api.discogs.com/releases/4976693', false, $context); 
?> 
Steve Bennett
  • 114,604
  • 39
  • 168
  • 219

2 Answers2

1
<?php 
echo file_get_contents(('http://api.discogs.com/releases/4976693'), false); 
?> 

This will work. You don't need to add any option.

Stéphane Bruckert
  • 21,706
  • 14
  • 92
  • 130
  • It works with any other URL, but not with Discogs API... It is said in Discogs API manual http://www.discogs.com/developers/accessing.html#required-headers that I must set proper "User-Agent" string in order to get data from their server. But it doesn't help, too. – Alexander Goldovsky Jan 29 '14 at 19:46
  • I found that somewhere, seems the author is the owner of hazadus.net. – Andy Thompson Feb 05 '14 at 10:41
0

If you're using PHP and want to connect to the Discogs API you probably want to use the client I wrote: https://github.com/ricbra/php-discogs-api

ricbra
  • 170
  • 6