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(7y ago)3111.6k↓89.3%53MITPHPPHP &gt;=7.1

Since Mar 28Pushed 7y ago1 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 yesterday

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 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community20

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

2561d ago

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

v0.8PHP &gt;=7.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/182812?v=4)[Pierre Q.](/maintainers/dandelionmood)[@dandelionmood](https://github.com/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

[mollie/mollie-api-php

Mollie API client library for PHP. Mollie is a European Payment Service provider and offers international payment methods such as Mastercard, VISA, American Express and PayPal, and local payment methods such as iDEAL, Bancontact, SOFORT Banking, SEPA direct debit, Belfius Direct Net, KBC Payment Button and various gift cards such as Podiumcadeaukaart and fashioncheque.

60216.0M85](/packages/mollie-mollie-api-php)[webit/w-firma-api

wFirma.pl API

1822.0k](/packages/webit-w-firma-api)[gabrielbull/ups-api

PHP UPS API

4572.4M11](/packages/gabrielbull-ups-api)[deepseek-php/deepseek-php-client

deepseek PHP client is a robust and community-driven PHP client library for seamless integration with the Deepseek API, offering efficient access to advanced AI and data processing capabilities.

46688.8k5](/packages/deepseek-php-deepseek-php-client)[tamara-solution/php-sdk

Tamara PHP Client Library

10278.3k1](/packages/tamara-solution-php-sdk)[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.

4262.9k](/packages/wtfzdotnet-php-tmdb-api)

PHPackages © 2026

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