Flex/ActionScript3 library of Last.fm's web services.
API methods: album.*, artist.*, auth.getSession, event.*, geo.*, group.*, library.*, playlist.*, radio.*, tag.*, tasteometer.*, track.*
... [More]
, user.*, venue.*.
Other Similar Projects:
http://code.google.com/p/lastfm-as3/ http://code.google.com/p/lastfm-as3-api/ News:
May 03, 2009
You can download latest library and its document here.
You can also checkout the source code (as a project in Flex Builder 3) with SVN. And as3-lastfm-web-services-test is its unit test (as a project in Flex Builder 3 as well).
The important classes are fm.last.LastFmService and fm.last.RestAPI. Each Last.fm's API method is implemented in fm.last.api.*.
Further reading: ImplementationIssue, UsageExample.
Any feedback, comment, suggestion is absolutely always welcome!!
Here is an example of desired usage.
package {
import fm.last.*;
import fm.last.api.*;
import fm.last.error.*;
import flash.display.Sprite;
import flash.events.*;
import flash.net.*;
public class LastFmServiceExample1 extends Sprite {
public function LastFmServiceExample1()
{
// example for artist.getSimilar http://www.last.fm/api/show?service=119
var lastfm:LastFmService = new LastFmService("an_api_key");
// get similar artistes of Cher
// the `onComplete` callback function will be called then
lastfm.artist.getSimilar(onComplete, onError, "cher");
// this call will result in an error,
// and the `onError` callback function will be called
lastfm.artist.getSimilar(onComplete, onError, "No_Such_Artist");
}
/** parameter is an XML document */
private function onComplete(response:XML):void
{
// an successful response could be...
/*
*
*
* Sonny & Cher
* 3d6e4b6d-2700-458c-9722-9021965a8164
* 100
* www.last.fm/music/Sonny%2B%2526%2BCher
* .....
*
*
* ...
*
*
*/
// we can trace the mbid `3d6e4b6d-2700-458c-9722-9021965a8164`
trace(response. similarartists.artist[0].mbid);
}
/** parameter is an ErrorEvent */
private function onError(e:ErrorEvent):void
{
trace(e.toString());
}
}
}Here is an example of those APIs requiring authentication.
package {
import fm.last.*;
import fm.last.api.*;
import fm.last.error.*;
import flash.display.Sprite;
import flash.events.*;
import flash.net.*;
public class LastFmServiceExample2 extends Sprite {
public function LastFmServiceExample2()
{
// example for auth.getSession http://www.last.fm/api/show?service=125
var lastfm:LastFmService = new LastFmService("an_api_key", "a_secret");
// how to get a "token" is outside the scope of this library
// you may get it manually or with JavaScript, etc.
lastfm.auth.getSession(onGetSession, onError, "a_token");
}
private function onGetSession(response:XML):void
{
// a successful response could be...
/*
*
*
* a_name
* a_session_key
* 0
*
*
*/
var sessionKey:String = response.session.key;
// now new a last.fm service with acquired session
var lastfmInSession:LastFmService =
new LastFmService("an_api_key", "a_secret", sessionKey);
// example for library.addArtist http://www.last.fm/api/show?service=371
// which requires authentication.
lastfmInSession.library.addArtist(onComplete, onError, "Björk");
}
private function onComplete(response:XML):void
{
// successful response is
trace(response.attribute("status")); // ok
}
private function onError(e:ErrorEvent):void
{
trace(e.toString());
}
}
} [Less]