Accessing Discogs API from PHP

1.6k Views Asked by At

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); 
?> 
2

There are 2 best solutions below

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

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

0
On

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