我想用musicbrainz来确定一首歌的首次发行日期。为了得到这个,我用的是Mikealmond MusicBrainz图书馆。
我遇到的问题是,当我试图执行与本例(https://github.com/mikealmond/MusicBrainz/blob/master/examples/first-recording-search.php)中完全相同的代码时,总是会得到一个身份验证错误。

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

因此,我试图将我的用户名和密码添加到请求中:
$brainz = new MusicBrainz(new GuzzleHttpAdapter(new Client()),'myusername','mypassword');
$brainz->setUserAgent('myapplicationname', '0.2', 'http://localhost:443/');

如果我手动调用错误消息中的url并输入用户名和密码,则会得到预期的数组。
我刚发现:如果我删除了-"+ user - ratings"-它不需要身份验证。
因此,我在我的项目中用"user - ratings"注释了这些行
现在我认为它可以工作了,但是查询的性能非常差,经常会出现错误503//MusicBrainzWeb服务器当前正忙。请稍后再试。//
一首歌需要几秒钟。有人知道这是正常的还是我还犯了什么错误?
我的代码…
//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));

$recorings我可以打印,在循环中我可以打印每个$recording,但是当我提取信息时出错
 /** @var $recording \MusicBrainz\Recording */
            foreach ($recordings as $recording) {
                // if the recording has a lower score than the previous recording, stop the loop.
                // This is because scores less than 100 usually don't match the search well
                if (null != $lastScore && $recording->getScore() < $lastScore) {
                    break;
                }
                $lastScore = $recording->getScore();
                $releaseDates = $recording->getReleaseDates();
                $oldestReleaseKey = key($releaseDates);
                if (strtoupper($recording->getArtist()->getName()) == strtoupper($args['artist'])
                    && $releaseDates[$oldestReleaseKey] < $firstRecording['releaseDate']
                ) {
                    $firstRecording = array(
                        'releaseDate' => $recording->releases[$oldestReleaseKey]->getReleaseDate()
                    );
                }
            }
            pr($firstRecording);
        } catch (Exception $e) {
            pr($e->getMessage());
        }

最佳答案

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

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

10-06 13:25