Download the PHP package dandelionmood/lastfm without Composer
On this page you can find all versions of the php package dandelionmood/lastfm. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dandelionmood/lastfm
More information about dandelionmood/lastfm
Files in dandelionmood/lastfm
Package lastfm
Short Description Dead simple wrapper for the Last.fm API.
License MIT
Homepage https://github.com/dandelionmood/php-lastfm
Informations about the package lastfm
Last.fm API PHP Wrapper
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 is very good, and you shoudn't need anything else to work with the API.
Installation
You should install it through Composer / Packagist, because … Well, it's awesome !
The package is available here on Packagist.
Standard methods (no authentication needed)
Let's dive into the meat of this project. First, you need to register your application to key an API key and secret.
Once it's done, here's how you get an instance to work with :
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 that will give us what we need (see here).
What you'll get in return is a standard PHP Object.
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
Please look in the 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 :
Secondly, we need to handle the callback URL that will be called when the user validates the form :
I decided to print out the session key, but you should keep it in a database or the variable : YMMV …
Authenticated methods
The user is now authenticated, we now know its ; we can use it as a third parameter when calling the constructor.
Here's a simple authenticated method that takes the in the URL and posts a message on my wall :
You need to add a third parameter when calling the function to let the API know it's an authenticated call.
Last words
You can generate the class documentation using the 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 . You can launch them by calling the command/