• PHP Last.fm API

    Update: version 0.2 - details

    I've been working on a simple set of classes so that people can use the Last.fm API in PHP without coding it all themselves.

    There is currently no documentation but there are examples for each supported API method in the examples folder of the download.

    It is licenced under the MIT open source license and released on SF.net so you can use it in basically any way you want as long as you give credit to the project for providing the classes (and not saying you wrote it yourself).

    You can get the alpha release from the sf.net project page and the website.

    Have fun with the classes and show me what you make in the last.fm group I setup.

    Useful Links:

    Project Website - http://phplastfmapi.sourceforge.net/
    SF.net Project Page - http://sourceforge.net/projects/phplastfmapi/
    Last.fm Group - http://www.last.fm/group/PHP+Last.fm+API/
    SVN Browser - http://phplastfmapi.svn.sourceforge.net/viewvc/phplastfmapi/
    SVN Access Documentation - http://sourceforge.net/svn/?group_id=236702

    Edit: Could a staff member change the download link for the class in the API documentation to the project website please. Thank you :)

    ONGOING PROJECT! PHP Last.FM API (Download or SVN)
    Online Last.FM Player (Updated version is SVN only currently)
    Modifié par lotrgamemast le 6 sept. 2008, 23h06m
    • raboof a dit :...
    • Utilisateur
    • 24 août 2008, 17h42m
    Impressive - did you write all that by hand or did you generate anything?

    I started on xsd's for the responses and generated Java classes and marshalling/unmarshalling code for those at http://lastfmapi.sf.net - only geo.getEvents and user.getTopArtists so far.

    I'll add a link to your project there, I'd love to cooperate as much as possible (though I don't have any specific ideas about that right now).

  • It's hand coded but the code for every method is a copy and paste job at the minute. I need to make the code reused a bit more to save space and make it easier to maintain.

    I've never really messed with XSD's really and I'd have no idea what to use them for. I'm assuming though it could be used to autogenerate classes that process the XML returned from the Last.fm API. Am I somewhere close?

    Thank you for the link, I'll put a link to your project when I update the website to something nice. At the minute It's just bare HTML with no CSS at all :S

    Matt

    ONGOING PROJECT! PHP Last.FM API (Download or SVN)
    Online Last.FM Player (Updated version is SVN only currently)
    • JRoar a dit :...
    • Équipe Last.fm
    • 24 août 2008, 20h57m
    I too thought about using XSD schemas to speed up things, but because of the little but omnipresent inconsistencies in the XML responses I decided to go Matt's way, hand coding and copy&paste-ing ;)
    so far I think it was the better choice than trying to write the XSD's all by my own :(

  • It didn't take all that long to code in the end. It was quick once I got a set layout for each of the methods.

    I've tidied up some of the code in the SVN version now by putting all the error related code into the base class. Not sure if it'll speed things up but it will make maintaining the code easier.

    ONGOING PROJECT! PHP Last.FM API (Download or SVN)
    Online Last.FM Player (Updated version is SVN only currently)
    • raboof a dit :...
    • Utilisateur
    • 25 août 2008, 5h34m
    I too thought about using XSD schemas to speed up things, but because of the little but omnipresent inconsistencies in the XML responses I decided to go Matt's way, hand coding and copy&paste-ing ;)
    I hadn't noticed this project before, added a link now.
    so far I think it was the better choice than trying to write the XSD's all by my own :(
    In the short run, copy-pasting code is probably faster than writing XSD's and generating code from that. On the other hand, in theory, the XSD's are more reusable (and perhaps could be used for things like generating bindings for other languages).

    • tburny a dit :...
    • Forum Moderator
    • 27 août 2008, 13h40m
    maybe you should send joanofarctan a PM for a link on API downloads page...
    I think many people can make use from your lib, so why not PM him? And the merchandise is really cool stuff btw(I won't say what, as it's a secret to be kept :P )...

    Combo.fm: Combine your favourite radio stations! | My Blog | scala-lastfmapi
    P.S.: Do not click here
    throw new PokemonException(); //Gotta catch 'em all
    My forum post reflects my personal opinion :)
  • I believe i'm already on the API downloads page but with the wrong URL. There was no mention of merch when I was added onto it though :( xD

    I'll PM him now.

    ONGOING PROJECT! PHP Last.FM API (Download or SVN)
    Online Last.FM Player (Updated version is SVN only currently)
    • concerthub a dit :...
    • Utilisateur
    • 28 août 2008, 16h57m
    lotrgamemast, many thanks for putting this together.

  • No problem, glad it's of some use. Only really made it to tune up my OOP skills in PHP; was starting to go stale from underuse :P

    ONGOING PROJECT! PHP Last.FM API (Download or SVN)
    Online Last.FM Player (Updated version is SVN only currently)
  • Version 0.2 has been released. It added support for all the write methods of the API as well as the 2 new methods that came out recently. Also included are 2 different sample applications; one which shows you which staff memember you are most like and another which finds the word that best describes a users musical taste.

    Please note that it won't be a drop in replacement when upgrading as the way in which you call all of the methods has been changed. Take a look at the examples to see how to do it now.

    Enjoy!!!!!

    ONGOING PROJECT! PHP Last.FM API (Download or SVN)
    Online Last.FM Player (Updated version is SVN only currently)
  • Am I totally mad, or missing something? It tells me I need auth.txt, correct? I create this file and see it needs to variables;

    'apiKey',
    'secret'
    'username'
    'sessionKey'
    'subscriber'

    But, I can't see how I'm supposed to define them? There is no example...

  • For most of the methods you only need the API key. However if the method required authentication you need all the different bits.

    The auth.txt is simply a way for the examples to work. You wouldn't use it this way in an actual application.

    To get the auth for a non-authenticated method (artist.getInfo, album.getTopTags etc) you should have code this this:

    $authVars = array(
    'apiKey' => YOURAPIKEYHERE
    );
    $auth = new lastfmApiAuth('setsession', $authVars);

    $apiClass = new lastfmApi();
    $artistClass = $apiClass->getPackage($auth, 'artist');

    You can then use the artistClass in the way shown in the examples.

    If the method requires full authentication though you'll need to do it slightly differently:

    $authVars = array(
    'apiKey' => 'fa3af76b9396d0091c9c41ebe3c63716',
    'secret' => 'f7df7cd6acf957521012f7a5f257d116',
    'token' => $_GET['token']
    );

    $auth = new lastfmApiAuth('getsession', $authVars);

    From this you will get all of the 5 variables that are written to auth.txt. However in a normal application you might want to store these in the database.

    I need to make the example a bit clearer and start working on the documentation to help people out a bit with using the API. Give me a few weeks.

    Hope this helped a bit!

    ONGOING PROJECT! PHP Last.FM API (Download or SVN)
    Online Last.FM Player (Updated version is SVN only currently)
  • Just a quick heads up that I've completely remade the website (shiny) and I've started work on the doumentation. The link is the same as above still.

    Any comments on it?

    ONGOING PROJECT! PHP Last.FM API (Download or SVN)
    Online Last.FM Player (Updated version is SVN only currently)
  • @lotrgamemast: This looks good. I've just updated the link on the downloads page so you should see that change on the site today. Some code usage examples in the documentation would be great.

    • angryOpium a dit :...
    • Utilisateur
    • 13 oct. 2008, 10h33m
    lotrgamemast The auth.txt is simply a way for the examples to work.

    but no one of your examles has one... so, they don't work! ;p

    And... @lotrgamemast. maybe u want to take a look at this: http://phpdoctor.sourceforge.net and this: http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_phpDocumentor.pkg.html

    --
    Stay Metal
    /opium
    • i-WiSH-i a dit :...
    • Utilisateur
    • 21 oct. 2008, 15h57m
    Thanks :)

    • bhogsett a dit :...
    • Abonné
    • 8 nov. 2008, 15h57m

    Get Session Key--Problem

    I am trying to start using the lastfmamp.php class.

    My first problem is unrelated to the class! I cannot get a session key. I do not understand how the parameters to auth.getsession are to be formatted. The documentation shows:

    e.g. http://ws.audioscrobbler.com/2.0/?method=auth.getsession&api_key=b25b959554ed76058ac220b7b2e0a026

    Params
    token (Required) : A 32-character ASCII hexadecimal MD5 hash returned by step 1 of the authentication process (following the granting of permissions to the application by the user)
    api_key (Required) : A Last.fm API key.
    api_sig (Required) : A Last.fm method signature. See authentication for more information.

    But it is unclear--at least to me--how to pass the token and api_sig. I have both.

    I have tried:

    http://ws.audioscrobbler.com/2.0/?method=auth.getsession&api_key=MYKEY&api_token=MYTOKEN FROM USER&api_sig=MYSIG.

    I generated the sig using the example in the documentation:

    api signature = md5("api_keyxxxxxxxxmethodauth.getSessiontokenxxxxxxx3")

    with the key and token being mine and the 3 being replaced with the secret key.

    I have tried variations of the formatting of the parameters, including:

    &api_key=MYKEYMYTOKEN FROM USERMYSIG (that is one long string)

    &api_key=MYKEYapi_token=MYTOKEN FROM USERapi_sig=MYSIG

    and probably others.

    So what is the format for the parameters to auth.getsession?

    Thanks.

    Bill Hogsett

    • bhogsett a dit :...
    • Abonné
    • 8 nov. 2008, 16h01m

    auth.txt format

    I am unclear of the auth.txt format. I think it is the following:

    api Key
    secret Key
    username
    session Key
    subscrber

    with each data item on a separate line without any key=value identification. So on the username line I would just have bhogsett.

    Is this correct?

    Are the items quoted? I assume not. Right?

    What is the difference between username and subscriber?

    Thanks.

    Bill Hogsett

  • For any confused about what the auth.txt file is look here:

    http://apps.sourceforge.net/mediawiki/phplastfmapi/index.php?title=FAQ#What_is_this_auth.txt_file_about.3F

    I haven't included it because the one I use is linked to my account and if I let you have it you can edit my tags and event information and so on. You basically need to run the auth example to create your own.

    ONGOING PROJECT! PHP Last.FM API (Download or SVN)
    Online Last.FM Player (Updated version is SVN only currently)
    • [Utilisateur supprimé] a dit :...
    • Utilisateur
    • 31 mars 2009, 21h11m
    In case if I want to get the biography of a band in Portuguese? What should I do?
    Thanks for advance.

    • periphery a dit :...
    • Utilisateur
    • 2 avr. 2009, 10h10m

    Many Thanks

    Thanks mate its a great class, i had a bit of downtime at work which gave me the opportunity to have a fiddle with it. After around 4 hours work i had it figured out and was able to make this nifty page.
    It basically just runs via cron job every 12 hours uses the geo location methods to pull the upcoming gigs which of course come back from last.fm with the longitude and latitude so then my script just writes them to a .kml file to be plotted to a map.

    • MusX a dit :...
    • Utilisateur
    • 14 juin 2009, 11h32m
    version 0.7
    user.php
    line 152
    'You must include artist variable in the call for this method'
    shouldn't be there 'user' instead of 'artist'?

    • mjhale a dit :...
    • Utilisateur
    • 21 oct. 2009, 2h25m
    Thanks for this, it has helped a lot!

    Recently an error popped up and I'm not sure how to go about fixing it (I've been trying for well over an hour).

    Fatal error: Class 'lastfmApi' not found in l/lastfmapi/api/radio.php on line 10

    If you could help me figure out what the problem is it would be much appreciated

    • fn0000rd a dit :...
    • Utilisateur
    • 5 avr. 2010, 0h40m

    Still working?

    Is this API still up to date?

    I can't get the auth example to work. I've updated the api key and the secret to use my own key and secret, but all of the vars are still coming up blank.

Les utilisateurs anonymes ne peuvent pas poster de messages. Merci de vous connecter ou de créer un compte pour pouvoir intervenir dans les forums.