Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从PHP访问discogsapi_Php_Json_Discogs Api - Fatal编程技术网

从PHP访问discogsapi

从PHP访问discogsapi,php,json,discogs-api,Php,Json,Discogs Api,我试图通过discogsapi获取JSON格式的发布数据,但它不起作用。我做错了什么?这段代码可以很好地与其他URL配合使用 <?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

我试图通过discogsapi获取JSON格式的发布数据,但它不起作用。我做错了什么?这段代码可以很好地与其他URL配合使用

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



这会奏效的。您不需要添加任何选项。

如果您使用的是PHP并希望连接到Discogs API,您可能希望使用我编写的客户端:

它适用于任何其他URL,但不适用于Discogs API。。。Discogs API手册中说,为了从他们的服务器获取数据,我必须设置适当的“用户代理”字符串。但这也没用。
<?php 
echo file_get_contents(('http://api.discogs.com/releases/4976693'), false); 
?>