Using the last.fm API

A friend of mine, Will McNeilly, over at glasgowpodcart mentioned to me that he was looking for some way to pull data from their site using their API. In particular he was interested in pulling out events related to specific groups and artists. After looking over the last.fm API I decided to give it a go, using the artist.getevents method, which generates an XML feed. From that it was a simple case of parsing the XML into a site using, in this case, the simpleXML function in PHP5. The code looks something like this:

<?php
$s=simplexml_load_file('http://ws.audioscrobbler.com/2.0/?method=artist.getevents&artist=Disturbed&api_key=b25b959554ed76058ac220b7b2e0a026');
foreach ($s->events->event as $event) {
	echo 'Event Title: '.$event->title."<br/>\n";
	foreach ($s->events->event->artists->artist as $artist) {
		echo 'Performing Artist: '.$artist."<br/>\n";
	}
	echo 'Venue Name: '.$event->venue->name."<br/>\n";
	echo 'Venue City: '.$event->venue->location->city."<br/>\n";
	echo 'More Information: <a href="'.$event->url.'" target="_blank">'.$event->url."</a><br/>\n";
}
?>

What this code does is pulls the XML feed into the page listing the latest events for the band Disturbed, and pulls various aspects out of the feed and displays them in a very rough and ready form. I've left it like this so that Will can slot it into the glasgowpodcart site and theme it however he sees fit.

View Result: Disturbed's Upcoming Events

Posted by Wulf on April 17, 2009, 7:43 pm

Comments on this Post

Sorry, no comments have been made