Unfortunately I haven't any experience in coding PHP. Just Html.
I'm trying to retrieve lyrics from Musixmatch without success.
This code below I'd used to retrieve successfully Bios from Last.fm, and to use with Musixmatch I've changed the values (url, api_key).
Can you give me a little help?
Thanks so much.
Merry Xmas.
<?php
$fields = array(
'q_track' => $track,
'q_artist' => $artist,
'api_key' => 'xxxxxecab2a0072c88ee31b50a4225b');
$fields_string = '';
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_URL,
'http://api.musixmatch.com/ws/1.1/matcher.lyrics.get');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01;
Windows NT 5.0)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$soap = simplexml_load_string($response); ?>
<div>
<div />
<h3><?php echo $track; ?></h3>
</div>
<br><div><p><?php print nl2br(strip_tags($soap->body->lyrics-
>lyrics_body)); ?></p><br></div>
1/ You're sending the request using POST
method which is not supported By the API. Try replacing the CURL
request by this:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,
'http://api.musixmatch.com/ws/1.1/matcher.lyrics.get?'.$fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
2/ The API's response type is JSON
, so try using json_decode()
instead of simplexml_load_string()
Alos, I recommend using HTTPS.