jfhovinne/phplastfm

该软件包已被 弃用 且不再维护。未建议替代软件包。

Last.fm API 客户端

dev-master 2015-12-26 18:10 UTC

This package is not auto-updated.

Last update: 2020-08-26 00:03:14 UTC


README

Last.fm PHP 客户端

安装

$ composer require jfhovinne/phplastfm:dev-master

使用

首先获取 Last.fm API 密钥,请参阅 http://www.last.fm/api

然后,通过传递 API 密钥实例化客户端

<?php
require __DIR__ . '/vendor/autoload.php';

use Lastfm\Client as LastfmClient;

$lastfmclient = new LastfmClient('your_api_key');

要调用 Last.fm API 方法并获取 JSON 格式的结果,请使用 callMethod($methodName, $parameters)

$json = $lastfmclient->callMethod('user.getTopTracks', ['user' => 'lastfm_username', 'limit' => '20']);

if (isset($json->error)) {
  echo($json->message);
} else {
  foreach($json->toptracks->track as $track) {
    echo($track->artist->name . ' - ' . $track->name . "\n");
  }
}