SlideShare une entreprise Scribd logo
1  sur  38
Télécharger pour lire hors ligne
Last.fm API
                         A brief introduction by David Singleton




Wednesday, 26 May 2010
What’s Last.fm?
                  • We do lots of things:
                         •   charts, recommendations, catalogue, radio, metadata,
                             similar artists, images, playlists, events, groups, tags,
                             venues, friends, journals, shoutboxes

                  • The “Social music revolution”, almost
                         entirely user generated content, so we
                         don’t like to keep it locked up
                  • Long history of offering APIs
Wednesday, 26 May 2010
Wednesday, 26 May 2010
Scrobbling
                  • For anyone who doesn’t know...
                   • It’s what we do, fundementally
                   • Not Scribbling, Scobbing, Snowballing or
                         Scrabbling. Scrobbling, to scrobble

                 scrobble: skrob· bul (ˈskrɒbəll)
                   [verb] To automatically add the tracks you play to your Last.fm
                   profile with a piece of software called a Scrobbler



Wednesday, 26 May 2010
Some scrobbling stats
                  • 571 scrobbles in the last second
                  • 34,260 scrobbles in the last minute
                  • 2,055,600 scrobbles in the last hour
                  • 24,667,200 scrobbles in the last 12 hours
                  • 49,334,400 scrobbles in the last day
                         That's over 34,925,934,051 tracks scrobbled since 2003.
                                  About 272,444 years of music in total.


Wednesday, 26 May 2010
API 2.0
                  • A REST-style HTTP API, that you (might)
                         know and love (modeled on Flickr)
                  • Full documentation at http://last.fm/api (far
                         more reliable than me...). Seriously, read
                         this, it’s pretty damn good.
                  • Clients written in PHP, Ruby, Python, C++
                  • Unrestricted non-commercial use
Wednesday, 26 May 2010
Documentation

                  • Complete and up to date documentation
                         can be found at http://last.fm/api
                  • Each method has a page that details is
                         required and optional parameters
                  • It covers everything here in greater depth,
                         and is generally extremely useful.



Wednesday, 26 May 2010
What does it offer?
                  • One hundred or so methods to access
                         information about:
                         • Artists, albums, tracks, tags, users,
                           playlists, events, venues, groups, radio
                         • Authenticated access to private data
                         • Export a users full listening history

Wednesday, 26 May 2010
album.addTags, album.getInfo, album.getTags, album.removeTag, album.search,
    artist.addTags, artist.getEvents, artist.getImages, artist.getInfo, artist.getPastEvents,
 artist.getPodcast, artist.getShouts, artist.getSimilar, artist.getTags, artist.getTopAlbums,
artist.getTopFans, artist.getTopTags, artist.getTopTracks, artist.removeTag, artist.search,
      artist.share, artist.shout, auth.getMobileSession, auth.getSession, auth.getToken,
        event.attend, event.getAttendees, event.getInfo, event.getShouts, event.share,
      event.shout, geo.getEvents, geo.getMetroArtistChart, geo.getMetroTrackChart,
                   geo.getMetroUniqueArtistChart, geo.getMetroUniqueTrackChart,
                 geo.getMetroWeeklyChartlist, geo.getTopArtists, geo.getTopTracks,
      group.getMembers, group.getWeeklyAlbumChart, group.getWeeklyArtistChart,
           group.getWeeklyChartList, group.getWeeklyTrackChart, library.addAlbum,
               library.addArtist, library.addTrack, library.getAlbums, library.getArtists,
      library.getTracks, playlist.addTrack, playlist.create, playlist.fetch, radio.getPlaylist,
       radio.tune, tag.getSimilar, tag.getTopAlbums, tag.getTopArtists, tag.getTopTags,
     tag.getTopTracks, tag.getWeeklyArtistChart, tag.getWeeklyChartList, tag.search,
        tasteometer.compare, track.addTags, track.ban, track.getInfo, track.getSimilar,
       track.getTags, track.getTopFans, track.getTopTags, track.love, track.removeTag,
                track.search, track.share, user.getEvents, user.getFriends, user.getInfo,
        user.getLovedTracks, user.getNeighbours, user.getPastEvents, user.getPlaylists,
        user.getRecentStations, user.getRecentTracks, user.getRecommendedArtists,
 user.getRecommendedEvents, user.getShouts, user.getTopAlbums, user.getTopArtists,
                     user.getTopTags, user.getTopTracks, user.getWeeklyAlbumChart,
    user.getWeeklyArtistChart, user.getWeeklyChartList, user.getWeeklyTrackChart,
Wednesday, 26 May 2010user.shout, venue.getEvents, venue.getPastEvents, venue.search
Or in an organised fashion...




Wednesday, 26 May 2010
Who uses the API?
                  • 1,000s of 3rd party developers every day
                   • Checkout http://build.last.fm for
                   • From forum sigs, to complex apps
                  • Microsoft built an Xbox360 app using only
                         our public API
                  • Squeezebox, Sonos and other hardware
                         devices


Wednesday, 26 May 2010
Hundreds of Scrobblers
                  • Hype Machine, Spotify, Songbird, Winamp,
                         iTunes and many more
                  • People have found ways to scrobble
                         Youtube, and even their vinyl collection
                  • You? Check out our submissions API too
                  • Question: as a developer what would make
                         scrobbling more appealing to you?


Wednesday, 26 May 2010
Wednesday, 26 May 2010
Wednesday, 26 May 2010
Wednesday, 26 May 2010
(Not just iPhone; Android and Blackberry too)
Wednesday, 26 May 2010
Using the API
                  • That’s why you’re here, right?
                  • You’ll need...
                   • An API Key (a 32 char unique identifier)
                   • A way to call the API (use a supported
                           client, or plain old wget, up to you)
                         • A way to parse the response (this is
                           where clients can come in handy)


Wednesday, 26 May 2010
Getting an API Key
                  • To get one you’ll need a last.fm account,
                         so if you don’t have one you’ll need to join
                  • Set it up at http://last.fm/api/account (you
                         probably non-commercial use)
                  • Only one API Key per account
                                 Please don’t use the example key



Wednesday, 26 May 2010
Anatomy of an API call

                  • http://ws.audioscrobbler.com/2.0/?
                         method=user.getinfo&api_key=XXX&user=
                         underpangs
                  • Root URL + Method + API Key + method
                         specific parameters (check the method
                         documentation)



Wednesday, 26 May 2010
Anatomy of a response
             <lfm status="ok">
                 <user>
                    <id>1021212</id>
                    <name>underpangs</name>
                    <realname>David Singleton</realname>
                    <url>http://www.last.fm/user/underpangs</url>
                    <image>http://userserve-ak.last.fm/serve/126/13884831.jpg</
               image>
                    <country>UK</country>
                    <age>25</age>
                    <gender>m</gender>
                    <subscriber>1</subscriber>
                    <playcount>45519</playcount>
                    <playlists>12</playlists>
                    <bootstrap>0</bootstrap>
                    <registered unixtime="1073173934">2004-01-03 23:52</registered>
                 </user>
             </lfm>


              Every response is wrapped in a root <lfm> node
Wednesday, 26 May 2010
Output Formats
                  • By default all services output XML are also
                         available as JSON
                  • To switch, add Add format=json to your call
                  • Some services offer even more output
                         formats, check the method docs
                         • Noteably some can output RSS, XSPF,
                           iCal and JSONP


Wednesday, 26 May 2010
JSON Output
             {
                 "user": {
                     "id": "1021212",
                     "name": "underpangs",
                     "realname": "David Singleton",
             [SNIP!]
                     "registered": {
                         "#text": "2004-01-03 23:52",
                         "unixtime": "1073173934"
                     }
                 }
             }


                         Note that for elements with both a text child and attributes,
                              that the text is expressed as the #text attribute



Wednesday, 26 May 2010
Paginated methods
                  • Some methods can return a lot of results,
                         we limit them and let you page through
                  • These services will generally accept a limit
                         (amount per page) and page offset. The
                         root node will also give you the total
                         number of results and pages
   <lfm status="ok" total="109" page="1" perPage="50" totalPages="3">
     ...
   </lfm>



Wednesday, 26 May 2010
Errors

                  • The root lfm node has a status of “failed”
                         and will contain an error code and message
                  • The possible errors for a method are listed
                         on it’s documentation page

                  <lfm status="failed">
                      <error code="10">Invalid API Key</error>
                  </lfm>




Wednesday, 26 May 2010
Common Errors

                  • Invalid format - This service doesn't exist in
                         that format
                  • Invalid parameters - Your request is missing
                         a required parameter
                  • Invalid API key
                  • Invalid method signature supplied
Wednesday, 26 May 2010
Common Methods
                  • artist.getImages
                  • album.getTags
                  • track.search
                  • user.getTopArtists
                  • geo.getEvents
                  • event.getInfo
Wednesday, 26 May 2010
Method “Types”

                  • Public - Does what it says on the tin
                  • Private - Requires authentication (which i’ll
                         get to shortly)
                  • “Enhanced” - Public, but with extra
                         information if you supply a user,
                         artist.getInfo is a good example of this



Wednesday, 26 May 2010
Let’s look at some live
                           example...


Wednesday, 26 May 2010
Caveats

                  • Send an identifiable user-agent
                  • Don’t hammer the API (check the TOS)
                  • Respect HTTP caching headers
                  • It can go down, so be flexible
                  • UTF-8 encoding assumed

Wednesday, 26 May 2010
Authenticated Calls
                  • Some methods access private data and
                         require explicit permission from a user
                  • To do this we use an oAuth model, where a
                         user will grant permission to an
                         application, in the form of a session key
                  • Slightly different ways to get a session key
                         for web, mobile and desktop


Wednesday, 26 May 2010
Radio
                  • Radio is an authenticated call, you’ll need a
                         user session key
                  • API-based radio is only available to
                         subscribers, sorry :(
                  • Full documentation for using this is
                         available at http://last.fm/api/radio
                  • However, here’s a quick introduction...
Wednesday, 26 May 2010
Tuning

                  • POST call, to API root, method=radio.tune
                  • The station is in the form of a Last.fm URL,
                         eg; lastfm://artist/cher/similarartists
                  • Once tuned, you request a playlist of 5
                         tracks at a time, with radio.getPlaylist which
                         returns an XSPF



Wednesday, 26 May 2010
<playlist version="1" xmlns="http://xspf.org/ns/0/">
             <title>+Cher+Similar+Artists</title>
             <creator>Last.fm</creator>
             <date>2007-11-26T17:34:38</date>
             <link rel="http://www.last.fm/expiry">3600</link>
             <trackList>
                 <track>
                     <location>http://play.last.fm/ ... .mp3</location>
                     <title>Two People (Live)</title>
                     <identifier>8212510</identifier>
                     <album>Tina Live In Europe</album>
                     <creator>Tina Turner</creator>
                     <duration>265000</duration>
                     <image>http:// ... .jpg</image>
                     <extension application="http://www.last.fm">
                          <artistpage>...</artistpage>
                          <albumpage>...</albumpage>
                          <trackpage>...</trackpage>
                     </extension>
                 </track>
                 ...
             </trackList>
         </playlist>

Wednesday, 26 May 2010
Things people have
                         made with our API
                                (That I love)




Wednesday, 26 May 2010
(All done with JSONP, no explicit authorization, no proxy service)

Wednesday, 26 May 2010
Wednesday, 26 May 2010
How can you use this?
                  • Some humble suggestions;
                   • Rich artist information, stats, bio, images
                   • Bootstrapping a users music taste
                   • Catalogue search, artists, albums, tracks
                  • The API is simple and flexible, so it’s really
                         up to you and your imagination


Wednesday, 26 May 2010
Fin. Questions?

                  • email: davids@last.fm
                  • twitter: dsingleton
                  • irc: dsingleton on #musichackday
                  • Or just come ask me in person

Wednesday, 26 May 2010

Contenu connexe

Similaire à Music Hackday Boston - The Last.fm API

Storm at Spotify
Storm at SpotifyStorm at Spotify
Storm at SpotifyNeville Li
 
WebRTC, RED and Janus @ ClueCon21
WebRTC, RED and Janus @ ClueCon21WebRTC, RED and Janus @ ClueCon21
WebRTC, RED and Janus @ ClueCon21Lorenzo Miniero
 
Apache Geode - The First Six Months
Apache Geode -  The First Six MonthsApache Geode -  The First Six Months
Apache Geode - The First Six MonthsAnthony Baker
 
Introduction to Open Source, Apache and Apache Way
Introduction to Open Source, Apache and Apache WayIntroduction to Open Source, Apache and Apache Way
Introduction to Open Source, Apache and Apache WaySrinath Perera
 
Multistream in Janus @ CommCon 2019
Multistream in Janus @ CommCon 2019Multistream in Janus @ CommCon 2019
Multistream in Janus @ CommCon 2019Lorenzo Miniero
 
ScaleCamp 2009 - Last.fm vs Xbox
ScaleCamp 2009 - Last.fm vs XboxScaleCamp 2009 - Last.fm vs Xbox
ScaleCamp 2009 - Last.fm vs Xboxdavidsingleton
 
Downtown SF Lucene/Solr Meetup: Developing Scalable Search for User Generated...
Downtown SF Lucene/Solr Meetup: Developing Scalable Search for User Generated...Downtown SF Lucene/Solr Meetup: Developing Scalable Search for User Generated...
Downtown SF Lucene/Solr Meetup: Developing Scalable Search for User Generated...Lucidworks
 
夜宴24期《这段时间》
夜宴24期《这段时间》夜宴24期《这段时间》
夜宴24期《这段时间》Koubei Banquet
 
Power to the People: Manipulating SharePoint with Client-Side JavaScript
Power to the People:  Manipulating SharePoint with Client-Side JavaScriptPower to the People:  Manipulating SharePoint with Client-Side JavaScript
Power to the People: Manipulating SharePoint with Client-Side JavaScriptPeterBrunone
 
Music recommendations API with Neo4j
Music recommendations API with Neo4jMusic recommendations API with Neo4j
Music recommendations API with Neo4jBoris Guarisma
 
lastfm contentdashboards project description
lastfm contentdashboards project descriptionlastfm contentdashboards project description
lastfm contentdashboards project descriptionGaurav Bhardwaj
 
Create great cncf user base from lessons learned from other open source com...
Create great cncf user base from   lessons learned from other open source com...Create great cncf user base from   lessons learned from other open source com...
Create great cncf user base from lessons learned from other open source com...Krishna-Kumar
 
Worldcat (and other) APIs
Worldcat (and other) APIsWorldcat (and other) APIs
Worldcat (and other) APIsspurioso
 
First Beat Media - Tehnologije na velikim projektima #tnt3
First Beat Media - Tehnologije na velikim projektima #tnt3First Beat Media - Tehnologije na velikim projektima #tnt3
First Beat Media - Tehnologije na velikim projektima #tnt3SICEF
 
OWASP 2013 APPSEC USA ZAP Hackathon
OWASP 2013 APPSEC USA ZAP HackathonOWASP 2013 APPSEC USA ZAP Hackathon
OWASP 2013 APPSEC USA ZAP HackathonSimon Bennetts
 
How to "Hack" the DSpace Community
How to "Hack" the DSpace CommunityHow to "Hack" the DSpace Community
How to "Hack" the DSpace CommunityTim Donohue
 
IT Systems for Knowledge Management used in Software Engineering (2010)
IT Systems for Knowledge Management used in Software Engineering (2010)IT Systems for Knowledge Management used in Software Engineering (2010)
IT Systems for Knowledge Management used in Software Engineering (2010)Peter Kofler
 

Similaire à Music Hackday Boston - The Last.fm API (20)

Apache Lucene 4
Apache Lucene 4Apache Lucene 4
Apache Lucene 4
 
Storm at Spotify
Storm at SpotifyStorm at Spotify
Storm at Spotify
 
WebRTC, RED and Janus @ ClueCon21
WebRTC, RED and Janus @ ClueCon21WebRTC, RED and Janus @ ClueCon21
WebRTC, RED and Janus @ ClueCon21
 
Apache Geode - The First Six Months
Apache Geode -  The First Six MonthsApache Geode -  The First Six Months
Apache Geode - The First Six Months
 
Introduction to Open Source, Apache and Apache Way
Introduction to Open Source, Apache and Apache WayIntroduction to Open Source, Apache and Apache Way
Introduction to Open Source, Apache and Apache Way
 
Multistream in Janus @ CommCon 2019
Multistream in Janus @ CommCon 2019Multistream in Janus @ CommCon 2019
Multistream in Janus @ CommCon 2019
 
ScaleCamp 2009 - Last.fm vs Xbox
ScaleCamp 2009 - Last.fm vs XboxScaleCamp 2009 - Last.fm vs Xbox
ScaleCamp 2009 - Last.fm vs Xbox
 
Downtown SF Lucene/Solr Meetup: Developing Scalable Search for User Generated...
Downtown SF Lucene/Solr Meetup: Developing Scalable Search for User Generated...Downtown SF Lucene/Solr Meetup: Developing Scalable Search for User Generated...
Downtown SF Lucene/Solr Meetup: Developing Scalable Search for User Generated...
 
夜宴24期《这段时间》
夜宴24期《这段时间》夜宴24期《这段时间》
夜宴24期《这段时间》
 
Power to the People: Manipulating SharePoint with Client-Side JavaScript
Power to the People:  Manipulating SharePoint with Client-Side JavaScriptPower to the People:  Manipulating SharePoint with Client-Side JavaScript
Power to the People: Manipulating SharePoint with Client-Side JavaScript
 
Html5 Apps
Html5 AppsHtml5 Apps
Html5 Apps
 
Music recommendations API with Neo4j
Music recommendations API with Neo4jMusic recommendations API with Neo4j
Music recommendations API with Neo4j
 
lastfm contentdashboards project description
lastfm contentdashboards project descriptionlastfm contentdashboards project description
lastfm contentdashboards project description
 
Create great cncf user base from lessons learned from other open source com...
Create great cncf user base from   lessons learned from other open source com...Create great cncf user base from   lessons learned from other open source com...
Create great cncf user base from lessons learned from other open source com...
 
Worldcat (and other) APIs
Worldcat (and other) APIsWorldcat (and other) APIs
Worldcat (and other) APIs
 
First Beat Media - Tehnologije na velikim projektima #tnt3
First Beat Media - Tehnologije na velikim projektima #tnt3First Beat Media - Tehnologije na velikim projektima #tnt3
First Beat Media - Tehnologije na velikim projektima #tnt3
 
OWASP 2013 APPSEC USA ZAP Hackathon
OWASP 2013 APPSEC USA ZAP HackathonOWASP 2013 APPSEC USA ZAP Hackathon
OWASP 2013 APPSEC USA ZAP Hackathon
 
How to "Hack" the DSpace Community
How to "Hack" the DSpace CommunityHow to "Hack" the DSpace Community
How to "Hack" the DSpace Community
 
IT Systems for Knowledge Management used in Software Engineering (2010)
IT Systems for Knowledge Management used in Software Engineering (2010)IT Systems for Knowledge Management used in Software Engineering (2010)
IT Systems for Knowledge Management used in Software Engineering (2010)
 
Music streams
Music streamsMusic streams
Music streams
 

Music Hackday Boston - The Last.fm API

  • 1. Last.fm API A brief introduction by David Singleton Wednesday, 26 May 2010
  • 2. What’s Last.fm? • We do lots of things: • charts, recommendations, catalogue, radio, metadata, similar artists, images, playlists, events, groups, tags, venues, friends, journals, shoutboxes • The “Social music revolution”, almost entirely user generated content, so we don’t like to keep it locked up • Long history of offering APIs Wednesday, 26 May 2010
  • 4. Scrobbling • For anyone who doesn’t know... • It’s what we do, fundementally • Not Scribbling, Scobbing, Snowballing or Scrabbling. Scrobbling, to scrobble scrobble: skrob· bul (ˈskrɒbəll) [verb] To automatically add the tracks you play to your Last.fm profile with a piece of software called a Scrobbler Wednesday, 26 May 2010
  • 5. Some scrobbling stats • 571 scrobbles in the last second • 34,260 scrobbles in the last minute • 2,055,600 scrobbles in the last hour • 24,667,200 scrobbles in the last 12 hours • 49,334,400 scrobbles in the last day That's over 34,925,934,051 tracks scrobbled since 2003. About 272,444 years of music in total. Wednesday, 26 May 2010
  • 6. API 2.0 • A REST-style HTTP API, that you (might) know and love (modeled on Flickr) • Full documentation at http://last.fm/api (far more reliable than me...). Seriously, read this, it’s pretty damn good. • Clients written in PHP, Ruby, Python, C++ • Unrestricted non-commercial use Wednesday, 26 May 2010
  • 7. Documentation • Complete and up to date documentation can be found at http://last.fm/api • Each method has a page that details is required and optional parameters • It covers everything here in greater depth, and is generally extremely useful. Wednesday, 26 May 2010
  • 8. What does it offer? • One hundred or so methods to access information about: • Artists, albums, tracks, tags, users, playlists, events, venues, groups, radio • Authenticated access to private data • Export a users full listening history Wednesday, 26 May 2010
  • 9. album.addTags, album.getInfo, album.getTags, album.removeTag, album.search, artist.addTags, artist.getEvents, artist.getImages, artist.getInfo, artist.getPastEvents, artist.getPodcast, artist.getShouts, artist.getSimilar, artist.getTags, artist.getTopAlbums, artist.getTopFans, artist.getTopTags, artist.getTopTracks, artist.removeTag, artist.search, artist.share, artist.shout, auth.getMobileSession, auth.getSession, auth.getToken, event.attend, event.getAttendees, event.getInfo, event.getShouts, event.share, event.shout, geo.getEvents, geo.getMetroArtistChart, geo.getMetroTrackChart, geo.getMetroUniqueArtistChart, geo.getMetroUniqueTrackChart, geo.getMetroWeeklyChartlist, geo.getTopArtists, geo.getTopTracks, group.getMembers, group.getWeeklyAlbumChart, group.getWeeklyArtistChart, group.getWeeklyChartList, group.getWeeklyTrackChart, library.addAlbum, library.addArtist, library.addTrack, library.getAlbums, library.getArtists, library.getTracks, playlist.addTrack, playlist.create, playlist.fetch, radio.getPlaylist, radio.tune, tag.getSimilar, tag.getTopAlbums, tag.getTopArtists, tag.getTopTags, tag.getTopTracks, tag.getWeeklyArtistChart, tag.getWeeklyChartList, tag.search, tasteometer.compare, track.addTags, track.ban, track.getInfo, track.getSimilar, track.getTags, track.getTopFans, track.getTopTags, track.love, track.removeTag, track.search, track.share, user.getEvents, user.getFriends, user.getInfo, user.getLovedTracks, user.getNeighbours, user.getPastEvents, user.getPlaylists, user.getRecentStations, user.getRecentTracks, user.getRecommendedArtists, user.getRecommendedEvents, user.getShouts, user.getTopAlbums, user.getTopArtists, user.getTopTags, user.getTopTracks, user.getWeeklyAlbumChart, user.getWeeklyArtistChart, user.getWeeklyChartList, user.getWeeklyTrackChart, Wednesday, 26 May 2010user.shout, venue.getEvents, venue.getPastEvents, venue.search
  • 10. Or in an organised fashion... Wednesday, 26 May 2010
  • 11. Who uses the API? • 1,000s of 3rd party developers every day • Checkout http://build.last.fm for • From forum sigs, to complex apps • Microsoft built an Xbox360 app using only our public API • Squeezebox, Sonos and other hardware devices Wednesday, 26 May 2010
  • 12. Hundreds of Scrobblers • Hype Machine, Spotify, Songbird, Winamp, iTunes and many more • People have found ways to scrobble Youtube, and even their vinyl collection • You? Check out our submissions API too • Question: as a developer what would make scrobbling more appealing to you? Wednesday, 26 May 2010
  • 16. (Not just iPhone; Android and Blackberry too) Wednesday, 26 May 2010
  • 17. Using the API • That’s why you’re here, right? • You’ll need... • An API Key (a 32 char unique identifier) • A way to call the API (use a supported client, or plain old wget, up to you) • A way to parse the response (this is where clients can come in handy) Wednesday, 26 May 2010
  • 18. Getting an API Key • To get one you’ll need a last.fm account, so if you don’t have one you’ll need to join • Set it up at http://last.fm/api/account (you probably non-commercial use) • Only one API Key per account Please don’t use the example key Wednesday, 26 May 2010
  • 19. Anatomy of an API call • http://ws.audioscrobbler.com/2.0/? method=user.getinfo&api_key=XXX&user= underpangs • Root URL + Method + API Key + method specific parameters (check the method documentation) Wednesday, 26 May 2010
  • 20. Anatomy of a response <lfm status="ok"> <user> <id>1021212</id> <name>underpangs</name> <realname>David Singleton</realname> <url>http://www.last.fm/user/underpangs</url> <image>http://userserve-ak.last.fm/serve/126/13884831.jpg</ image> <country>UK</country> <age>25</age> <gender>m</gender> <subscriber>1</subscriber> <playcount>45519</playcount> <playlists>12</playlists> <bootstrap>0</bootstrap> <registered unixtime="1073173934">2004-01-03 23:52</registered> </user> </lfm> Every response is wrapped in a root <lfm> node Wednesday, 26 May 2010
  • 21. Output Formats • By default all services output XML are also available as JSON • To switch, add Add format=json to your call • Some services offer even more output formats, check the method docs • Noteably some can output RSS, XSPF, iCal and JSONP Wednesday, 26 May 2010
  • 22. JSON Output { "user": { "id": "1021212", "name": "underpangs", "realname": "David Singleton", [SNIP!] "registered": { "#text": "2004-01-03 23:52", "unixtime": "1073173934" } } } Note that for elements with both a text child and attributes, that the text is expressed as the #text attribute Wednesday, 26 May 2010
  • 23. Paginated methods • Some methods can return a lot of results, we limit them and let you page through • These services will generally accept a limit (amount per page) and page offset. The root node will also give you the total number of results and pages <lfm status="ok" total="109" page="1" perPage="50" totalPages="3"> ... </lfm> Wednesday, 26 May 2010
  • 24. Errors • The root lfm node has a status of “failed” and will contain an error code and message • The possible errors for a method are listed on it’s documentation page <lfm status="failed"> <error code="10">Invalid API Key</error> </lfm> Wednesday, 26 May 2010
  • 25. Common Errors • Invalid format - This service doesn't exist in that format • Invalid parameters - Your request is missing a required parameter • Invalid API key • Invalid method signature supplied Wednesday, 26 May 2010
  • 26. Common Methods • artist.getImages • album.getTags • track.search • user.getTopArtists • geo.getEvents • event.getInfo Wednesday, 26 May 2010
  • 27. Method “Types” • Public - Does what it says on the tin • Private - Requires authentication (which i’ll get to shortly) • “Enhanced” - Public, but with extra information if you supply a user, artist.getInfo is a good example of this Wednesday, 26 May 2010
  • 28. Let’s look at some live example... Wednesday, 26 May 2010
  • 29. Caveats • Send an identifiable user-agent • Don’t hammer the API (check the TOS) • Respect HTTP caching headers • It can go down, so be flexible • UTF-8 encoding assumed Wednesday, 26 May 2010
  • 30. Authenticated Calls • Some methods access private data and require explicit permission from a user • To do this we use an oAuth model, where a user will grant permission to an application, in the form of a session key • Slightly different ways to get a session key for web, mobile and desktop Wednesday, 26 May 2010
  • 31. Radio • Radio is an authenticated call, you’ll need a user session key • API-based radio is only available to subscribers, sorry :( • Full documentation for using this is available at http://last.fm/api/radio • However, here’s a quick introduction... Wednesday, 26 May 2010
  • 32. Tuning • POST call, to API root, method=radio.tune • The station is in the form of a Last.fm URL, eg; lastfm://artist/cher/similarartists • Once tuned, you request a playlist of 5 tracks at a time, with radio.getPlaylist which returns an XSPF Wednesday, 26 May 2010
  • 33. <playlist version="1" xmlns="http://xspf.org/ns/0/"> <title>+Cher+Similar+Artists</title> <creator>Last.fm</creator> <date>2007-11-26T17:34:38</date> <link rel="http://www.last.fm/expiry">3600</link> <trackList> <track> <location>http://play.last.fm/ ... .mp3</location> <title>Two People (Live)</title> <identifier>8212510</identifier> <album>Tina Live In Europe</album> <creator>Tina Turner</creator> <duration>265000</duration> <image>http:// ... .jpg</image> <extension application="http://www.last.fm"> <artistpage>...</artistpage> <albumpage>...</albumpage> <trackpage>...</trackpage> </extension> </track> ... </trackList> </playlist> Wednesday, 26 May 2010
  • 34. Things people have made with our API (That I love) Wednesday, 26 May 2010
  • 35. (All done with JSONP, no explicit authorization, no proxy service) Wednesday, 26 May 2010
  • 37. How can you use this? • Some humble suggestions; • Rich artist information, stats, bio, images • Bootstrapping a users music taste • Catalogue search, artists, albums, tracks • The API is simple and flexible, so it’s really up to you and your imagination Wednesday, 26 May 2010
  • 38. Fin. Questions? • email: davids@last.fm • twitter: dsingleton • irc: dsingleton on #musichackday • Or just come ask me in person Wednesday, 26 May 2010