PHPackages                             dandelionmood/lastfm - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. dandelionmood/lastfm

AbandonedArchivedLibrary[API Development](/categories/api)

dandelionmood/lastfm
====================

Dead simple wrapper for the Last.fm API.

v0.8(6y ago)3111.5k↓50%53MITPHPPHP &gt;=7.1

Since Mar 28Pushed 6y ago4 watchersCompare

[ Source](https://github.com/dandelionmood/php-lastfm)[ Packagist](https://packagist.org/packages/dandelionmood/lastfm)[ Docs](https://github.com/dandelionmood/php-lastfm)[ RSS](/packages/dandelionmood-lastfm/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (3)Versions (10)Used By (3)

Last.fm API PHP Wrapper
=======================

[](#lastfm-api-php-wrapper)

Introduction
------------

[](#introduction)

When I looked for an API to work with Last.fm API, I could only find either incomplete implementations or very complicated ones. I love simple things so I decided to take my chance and design a simple class that could do everything in the most simple way.

*The key idea is that the [official documentation](http://www.lastfm.fr/api)is very good, and you shoudn't need anything else to work with the API.*

Installation
------------

[](#installation)

You should install it through Composer / Packagist, because … [Well, it's awesome](http://getcomposer.org/doc/00-intro.md) !

The package is available [here on Packagist](https://packagist.org/packages/dandelionmood/lastfm).

Standard methods (no authentication needed)
-------------------------------------------

[](#standard-methods-no-authentication-needed)

Let's dive into the meat of this project. First, you need to [register your application](http://www.lastfm.fr/api/accounts)to key an API key and secret.

Once it's done, here's how you get an instance to work with :

```
// The secret is only needed if you want to access authenticated methods
$lastfm = new \Dandelionmood\LastFm\LastFm( $lastfm_api_key, $lastfm_api_secret );
```

Now let's say you want to get info on a given artist ? If you look into the API documentation, you can find the method `artist.getInfo` that will give us what we need ([see here](http://www.lastfm.fr/api/show/artist.getInfo)).

```
// Note that the dot is replaced by an underscore in the PHP API.
$pink_floyd = $lastfm->artist_getInfo(
	array(
		'artist' => 'Pink Floyd'
	)
);
```

What you'll get in return is a standard PHP Object.

Authenticated methods
---------------------

[](#authenticated-methods)

Some methods requires you to authenticate the user first. The PHP API gives you two methods to do this. This is very similar to OAuth and OpenID authentication, so if you've every implemented it before, you should feel right at home.

### Authentication

[](#authentication)

Please look in the `examples/authentication.php` file to find a Slim application implementing it. I will use portions of this file here to guide you step by step.

First, we need to ask the user to allow our application, this is handled by Last.fm ; they need to know what URL to call when the user says yes :

```
$app->get('/auth/connect', function() use($app) {
	$lastfm = new LastFm( LASTFM_API_KEY, LASTFM_API_SECRET );

	// We need to compute a callback URL that will be called when the user
	// allows the application.
	$callback_url = $lastfm->auth_get_url(
		$app->request()->getUrl()
			.$app->urlFor('auth_callback')
	);

	$app->redirect( $callback_url );
});
```

Secondly, we need to handle the callback URL that will be called when the user validates the form :

```
$app->get('/auth/callback', function() use($app) {

	$lastfm = new LastFm( LASTFM_API_KEY, LASTFM_API_SECRET );
	$token = $app->request()->get('token');

	try {
		// We try to get a session using the token we're given
		$session = $lastfm->auth_get_session( $token );
		echo "Yes ! The session key is : $session->session->key";
	} catch( Exception $e ) {
		echo "Sorry, something went wrong : ".$e->getMessage();
	}

})->name('auth_callback');
```

I decided to print out the session key, but you should keep it in a database or the `$_SESSION` variable : YMMV …

### Authenticated methods

[](#authenticated-methods-1)

The user is now authenticated, we now know its `session_key` ; we can use it as a third parameter when calling the constructor.

```
$lastfm = new LastFm( LASTFM_API_KEY, LASTFM_API_SECRET, $session_key );
```

Here's a simple authenticated method that takes the `session_id` in the URL and posts a message on my wall :

```
$app->get('/shout/:session_key', function($session_key) use($app) {

	// This time, note that we pass a third parameter, which is the session
	// key. This will allow us to call methods that need authentication.
	$lastfm = new LastFm( LASTFM_API_KEY, LASTFM_API_SECRET, $session_key );

	// We try to publish something on my wall.
	// Note the «true» in the last parameter, this tells the class that it's
	// a call that need authentication (session_key + signature are added).
	$r = $lastfm->user_shout(array(
		'user' => 'dandelionmood',
		'message' => "I just installed your Last.fm API wrapper :) !"
	), true);

	// We print a message to let know everything worked out allright !
	echo "A message has been successfully posted to 'dandelionmood' wall :) !";
	echo ''.print_r($r, true).'';

})->name('shout');
```

You need to add a third parameter when calling the `shout()` function to let the API know it's an authenticated call.

Last words
----------

[](#last-words)

You can generate the class documentation using the `./apigen` command.

The unit tests are very scarce at the moment, but they should work if you specify your own api key and secret, look in `tests/LastFmTest.php`. You can launch them by calling the `./phpunit` command/

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community22

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 58.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~326 days

Recently: every ~428 days

Total

8

Last Release

2515d ago

PHP version history (2 changes)v0.1PHP &gt;=5.3.0

v0.8PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/e0226d48672e9b63997b511cf7448ce9cf670ecbc6499f9c602d99d70f8de6ea?d=identicon)[dandelionmood](/maintainers/dandelionmood)

---

Top Contributors

[![dandelionmood](https://avatars.githubusercontent.com/u/182812?v=4)](https://github.com/dandelionmood "dandelionmood (10 commits)")[![lostfocus](https://avatars.githubusercontent.com/u/45055?v=4)](https://github.com/lostfocus "lostfocus (3 commits)")[![nickshears](https://avatars.githubusercontent.com/u/4777199?v=4)](https://github.com/nickshears "nickshears (2 commits)")[![lenielsen](https://avatars.githubusercontent.com/u/4314953?v=4)](https://github.com/lenielsen "lenielsen (1 commits)")[![phuedx](https://avatars.githubusercontent.com/u/191857?v=4)](https://github.com/phuedx "phuedx (1 commits)")

---

Tags

apiwrapperlastlast.fmfm

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dandelionmood-lastfm/health.svg)

```
[![Health](https://phpackages.com/badges/dandelionmood-lastfm/health.svg)](https://phpackages.com/packages/dandelionmood-lastfm)
```

###  Alternatives

[gabrielbull/ups-api

PHP UPS API

4642.4M10](/packages/gabrielbull-ups-api)[wtfzdotnet/php-tmdb-api

PHP wrapper for TMDB (TheMovieDatabase) API v3. Supports two types of approaches, one modelled with repositories, models and factories. And the other by simple array access to RAW data from The Movie Database.

4252.9k](/packages/wtfzdotnet-php-tmdb-api)[dariusiii/tmdb-laravel

Laravel Package for TMDB ( The Movie Database ) API. Provides easy access to the wtfzdotnet/php-tmdb-api library.

1821.1k](/packages/dariusiii-tmdb-laravel)[webit/w-firma-api

wFirma.pl API

1820.2k](/packages/webit-w-firma-api)[walle89/swedbank-json

Unofficial API client for the Swedbank's and Sparbanken's mobile apps in Sweden.

752.5k](/packages/walle89-swedbank-json)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
