【问题标题】:Accessing Discogs API from PHP从 PHP 访问 Discogs API
【发布时间】:2014-02-21 19:51:14
【问题描述】:

我正在尝试通过 Discogs API 以 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 json discogs-api


    【解决方案1】:

    如果您使用 PHP 并想连接到 Discogs API,您可能想使用我编写的客户端: https://github.com/ricbra/php-discogs-api

    【讨论】:

      【解决方案2】:
      <?php 
      echo file_get_contents(('http://api.discogs.com/releases/4976693'), false); 
      ?> 
      

      这会奏效。您无需添加任何选项。

      【讨论】:

      • 它适用于任何其他 URL,但不适用于 Discogs API...在 Discogs API 手册discogs.com/developers/accessing.html#required-headers 中说我必须设置正确的“User-Agent”字符串才能从中获取数据他们的服务器。但这也无济于事。
      • api.discogs.com/releases/4976693'; $ch = curl_init(); curl_setopt($ch, CURLOPT_USERAGENT, 'TheVinylCrate/1.0 +hazadus.net'); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close ($ch);回声$输出; ?> 我在某处发现,似乎作者是 hazadus.net 的所有者。
      猜你喜欢
      • 1970-01-01
      • 2015-03-12
      • 2015-05-23
      • 1970-01-01
      • 1970-01-01
      • 2017-02-16
      • 2019-01-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多