Create Affiliate ID
Code samples below do not contain a valid Affiliate ID. Create an Affiliate account before using these.
Real sample code:
- PHP class to use our webservice View and download
- Top 10 View in action and download
- Search View in action and download
- Artist List View in action and download
Copied!
<?php
require_once(__DIR__ . '/KVService.php');
header("Content-Type: text/html; charset=UTF-8");
// Display the form
echo '<h1>Search</h1>';
echo '<form method="POST">';
echo '<label>Query: <input type="text" name="query" value="' . (isset($_POST['query']) ? trim($_POST['query']) : '') . '" /></label>';
echo '<input type="submit" value="Search">';
echo '</form>';
if (isset($_POST['query']) && strlen(trim($_POST['query'])) > 0) {
$userQuery = trim($_POST['query']);
// Query to get the Top 10 Songs
$querySearch = array(
"function" => "song",
"parameters" => array("query" => $userQuery)
);
// Get the songs back form the service
$searchResult = KVService::querySearch($querySearch);
if ($searchResult->length == 0) {
echo '<p>No result found for query "' . $userQuery . '".</p>';
} else {
echo "<ol>";
foreach ($searchResult->songs as $song) {
// Get the artist of the song
$queryArtist = array(
"function" => "get",
"parameters" => array("id" => $song->artistId)
);
$artist = KVService::queryArtist($queryArtist)->artist;
echo '<li>
<a href="' . $song->url . '">' . $artist->name . ' - ' . $song->name . '</a> | <a href="' . $song->previewUrl . '">Preview</a>
</li>';
}
echo "</ol>";
}
}