To be able to change the now playing track you have to send "api_sig" as a post parameter in your request (see in the last.fm documentation). I am building this string as described in the documentation, but still, I always get an error: "Invalid Method - No method with that name in this package". However, I don't think, that the method doesn't exist, I think, that my api_sig is not correct as there's no error code for a wrong api_sig and I can't update other methods (f.e. track.scrobble).
This is my code so far (I know it's not very clean.. will get changed as soon as it works :D):
$url = 'http://ws.audioscrobbler.com/2.0/?api_key='.$apikey.'&format=json';
$params = array(
"api_key" => $apikey,
"method" => "track.updateNowPlaying",
"artist" => "eiffel65",
"track" => "Blue",
"sk" => $sessionkey
);
ksort($params);
$sigstr = "";
foreach ($params as $x => $x_value) {
$sigstr .= $x.$x_value;
}
$params = array(
"api_key" => urlencode($apikey),
"method" => urlencode("track.updateNowPlaying"),
"artist" => urlencode("eiffel65"),
"track" => urlencode("Blue"),
"sk" => urlencode($sessionkey)
);
$sigstr .= $apisecret;
$sigstr = md5(utf8_encode($sigstr));
$curl = curl_init();
$headers = array();
$params["api_sig"] = $sigstr;
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
$json = curl_exec($curl);
curl_close($curl);
I'd appreciate any tips and/or code snippets to help me out with my issue!