PHP MusicBrainz获得第一个发布日期

时间:2016-02-18 15:50:10

标签: php musicbrainz

我正在尝试使用Musicbrainz获得一首歌的第一个发布日期。为了得到这个,我正在使用mikealmond musicBrainz库。

我遇到的问题是,当我尝试执行与此示例中完全相同的代码(https://github.com/mikealmond/MusicBrainz/blob/master/examples/first-recording-search.php)时,我总是会收到身份验证错误。

build-essential

因此我尝试将我的用户名和密码添加到请求中:

Client error response [status code] 401 [reason phrase] Unauthorized [url] http://musicbrainz.org/ws/2/artist/0383dadf-2a4e-4d10-a46a-e9e041da8eb3?inc=releases+recordings+release-groups+user-ratings&fmt=json

如果我手动调用错误消息中的url并输入我的用户名和密码,我会得到我期望的数组。

我刚发现:如果我删除了 - $brainz = new MusicBrainz(new GuzzleHttpAdapter(new Client()),'myusername','mypassword'); $brainz->setUserAgent('myapplicationname', '0.2', 'http://localhost:443/'); - 它不需要身份验证。

因此,我在项目

中评论了"+ user - ratings"的行

现在我认为它有效,但查询的性能非常糟糕,我经常得到错误503 // MusicBrainz网络服务器目前正忙。请稍后再试。 //   一首歌只需几秒钟。有人知道这是正常还是我还有某种错误?

我的代码......

"user - ratings"

$ RECings我可以打印并在循环中我可以打印每个$录音,但错误来自我提取信息

//Create new MusicBrainz object
    $brainz = new MusicBrainz(new GuzzleHttpAdapter(new Client()), 'username', 'password');
    $brainz->setUserAgent('applicationname', '0.2', 'http://localhost:443/');

    // set defaults
    $artistId = null;
    $songId = null;
    $lastScore = null;
    $firstRecording = array(
        'releaseDate' => new DateTime()
    );
    // Set the search arguments to pass into the RecordingFilter
    $args = array(
        "recording" => 'we will rock you',
        "artist" => 'Queen',
    );
    try {
        // Find all the recordings that match the search and loop through them
        $recordings = $brainz->search(new RecordingFilter($args));

1 个答案:

答案 0 :(得分:0)

 $brainz = new MusicBrainz(new GuzzleHttpAdapter(new Client()), 'username', 'password');

您必须设置MusicBrainz帐户凭据。用您的帐户用户名替换“用户名”,并用用于登录MusicBrainz.org的密码替换“密码”