1

Last.FM API から JSON アルバム データを定期的に取得しようとしていますが、JSONP をサポートしていないため、クロスドメインの制限を回避するために PHP プロキシを使用しています。ここに私のPHPプロキシがあります:

<?php
$artist = $_GET["artist"];
$album = $_GET["album"];
$content = file_get_contents('http://ws.audioscrobbler.com/2.0/?method=album.getinfo&api_key=APIKEY=' . $artist . '&album=' . $album . '&format=json');
echo $content;
?>

ご覧のとおり、GET を使用してアーティストとアルバムを指定しているため、URL は次のようになります。albumartproxy.php?artist=Jake%20Bugg&album=Jake%20Bugg

しかし、プロキシを実行しようとすると、何らかの理由で次のエラーが発生します。

Warning: file_get_contents(http://ws.audioscrobbler.com/2.0/?method=album.getinfo&api_key=037358e302c80571663e6a7a66b1dc05&artist=Jake Bugg&album=Jake Bugg&format=json) [function.file-get-contents]: failed to open stream: HTTP request failed! in /MYDOMAIN/albumartproxy.php on line 6

API URL に直接アクセスすると機能しますか? 誰か助けてくれませんか?私は何を間違っていますか?

4

2 に答える 2

0

urlencode()リクエストとともに渡す GET パラメータが必要になります。

于 2013-07-06T03:27:22.300 に答える
0

GET次のようにurlencode() が必要です。

<?php

$apikey = "273f3dc84c2d55501f3dc25a3d61eb39";

$artist = urlencode($_GET["artist"]);
$album = urlencode($_GET["album"]);
$autocorrect = 0;

$content = "http://ws.audioscrobbler.com/2.0/?method=album.getinfo&api_key=".$apikey."&artist=".$artist."&album=".$album."&autocorrect=".$autocorrect;

echo file_get_contents($content);

?>

出力例: http://pastie.org/8114551

お役に立てれば!

于 2013-07-06T03:46:07.087 に答える