Created
April 18, 2011 20:40
-
-
Save mloberg/926122 to your computer and use it in GitHub Desktop.
Last.fm Simple PHP Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include_once('lastfm.php'); | |
$lastfm = new LastFm('your-api-key'); | |
$params = array( | |
'user' => 'mloberg' | |
); | |
print_r($lastfm->call('user.getInfo', $params)); | |
$tracks = $lastfm->call('user.getRecentTracks', $params); | |
foreach($tracks['recenttracks']['track'] as $track){ | |
echo $track['name'].' by '.$track['artist']['#text'].'<br />'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This simple last.fm php class was written by Matthew Loberg (http://mloberg.com) | |
*/ | |
class LastFm{ | |
private $api_key; | |
const url = 'http://ws.audioscrobbler.com/2.0/'; | |
function __construct($api_key){ | |
$this->api_key = $api_key; | |
} | |
function call($method,$params=array()){ | |
$lastfm = self::url.'?method='.$method.'&format=json&api_key='.$this->api_key; | |
foreach($params as $key => $value){ | |
$lastfm .= '&'.$key.'='.urlencode($value); | |
} | |
$json = file_get_contents($lastfm); | |
return json_decode($json, true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment