matto1990/lastfm-api

Last.fm Web服务客户端

v1.6.4 2019-06-14 07:38 UTC

This package is not auto-updated.

Last update: 2024-09-28 08:50:57 UTC


README

感谢您使用 PHP Last.FM API!

您需要在 http://www.last.fm/api 注册以获取自己的 API 密钥: http://www.last.fm/api

安装

composer require matto1990/lastfm-api

用法

use LastFmApi\Api\AuthApi;
use LastFmApi\Api\ArtistApi;

class LastFm
{
    private $apiKey;
    private $artistApi;

    public function __construct()
    {
        $this->apiKey = 'apikeyfromlastfm'; //required
        $auth = new AuthApi('setsession', array('apiKey' => $this->apiKey));
        $this->artistApi = new ArtistApi($auth);
    }
    public function getBio($artist)
    {
        $artistInfo = $this->artistApi->getInfo(array("artist" => $artist));

        return $artistInfo['bio'];
    }	
}

测试

要成功运行 phpunit,必须在 tests/Api 中包含 .env 文件。

lastfm_api_key=
lastfm_api_secret=
lastfm_token=
lastfm_session_key=
lastfm_username=

如果您只想运行不需要身份验证的测试: vendor/bin/phpunit --group notAuthenticated。在这种情况下,您只需要设置 lastfm_api_key 属性。