Hi all,

I am trying to work with Songkicks API to display the bands events from a list on my web page.

I've queried the artists names and now want to get specific data from this link

http://api.songkick.com/api/3.0/search/artists.json?query={$songkick_artist}&apikey=MYKEYGOESHERE\

The output get this result:

{"resultsPage":{"results":{"artist":[{"uri":"http:\/\/www.songkick.com\/artists\/200900-coheed-and-cambria?utm_source=4361&utm_medium=partner","displayName":"Coheed and Cambria","id":200900,"onTourUntil":"2011-09-23","identifier":[{"href":"http:\/\/api.songkick.com\/api\/3.0\/artists\/mbid:ae1b47d5-5128-431c-9d30-e08fd90e0767.json","eventsHref":"http:\/\/api.songkick.com\/api\/3.0\/artists\/mbid:ae1b47d5-5128-431c-9d30-e08fd90e0767\/calendar.json","mbid":"ae1b47d5-5128-431c-9d30-e08fd90e0767","setlistsHref":"http:\/\/api.songkick.com\/api\/3.0\/artists\/mbid:ae1b47d5-5128-431c-9d30-e08fd90e0767\/setlists.json"}]},{"uri":"http:\/\/www.songkick.com\/artists\/2060710-coheed-and-amp-cambria?utm_source=4361&utm_medium=partner","displayName":"Coheed & Cambria","id":2060710,"onTourUntil":null,"identifier":[]},{"uri":"http:\/\/www.songkick.com\/artists\/3236471-coheed-und-cambria?utm_source=4361&utm_medium=partner","displayName":"Coheed Und Cambria","id":3236471,"onTourUntil":null,"identifier":[]}]},"totalEntries":3,"perPage":50,"page":1,"status":"ok"}}

I need to get that first uri and use this as my link... How do I do this?

Any help on this would be greatly appreciated. Thanks for the time...

What the api is returning is a JSON string output which can be parsed using json_decode()

More details: http://www.php.net/manual/en/function.json-decode.php

$json = '{"resultsPage":{"results":{"artist":[{"uri":"http:\/\/www.songkick.com\/artists\/200900-coheed-and-cambria?utm_source=4361&utm_medium=partner","displayName":"Coheed and Cambria","id":200900,"onTourUntil":"2011-09-23","identifier":[{"href":"http:\/\/api.songkick.com\/api\/3.0\/artists\/mbid:ae1b47d5-5128-431c-9d30-e08fd90e0767.json","eventsHref":"http:\/\/api.songkick.com\/api\/3.0\/artists\/mbid:ae1b47d5-5128-431c-9d30-e08fd90e0767\/calendar.json","mbid":"ae1b47d5-5128-431c-9d30-e08fd90e0767","setlistsHref":"http:\/\/api.songkick.com\/api\/3.0\/artists\/mbid:ae1b47d5-5128-431c-9d30-e08fd90e0767\/setlists.json"}]},{"uri":"http:\/\/www.songkick.com\/artists\/2060710-coheed-and-amp-cambria?utm_source=4361&utm_medium=partner","displayName":"Coheed & Cambria","id":2060710,"onTourUntil":null,"identifier":[]},{"uri":"http:\/\/www.songkick.com\/artists\/3236471-coheed-und-cambria?utm_source=4361&utm_medium=partner","displayName":"Coheed Und Cambria","id":3236471,"onTourUntil":null,"identifier":[]}]},"totalEntries":3,"perPage":50,"page":1,"status":"ok"}}';

//var_dump(json_decode($json));
$array = json_decode($json, true); // passing the 2nd parameter as TRUE returns an associative array
print_r($array);
// in your case the uri can be directly accessed using
echo $array['resultsPage']['results']['artist'][0]['uri'];

hi jigarvyas and thank you much for the reply. Since all the links will be unique for a chosen artist I need to input something like:

// First, get the artist from the Loop
$artist = str_replace(' ', '+', $artist);

// Now, get the info ready to extract what we need 
$Link = "<a target=\"_blank\" class=\"tipsheet\" href=\"http://api.songkick.com/api/3.0/search/artists.json?query={$artist}&apikey=qeQKBP7qyvJ9tru5\"><img src=\"images/Logo.jpg\" height=\"25\" border=\"0\"></a>";

This is where I get stuck in passing the info you helped with through the looped links so that it goes directly to the proper page. The link now will get the "resultsPage" from every band similar to what I posted earlier but I would like it to go to the results uri link generated from the query.

Perhaps I am thinking too much about this I don't know but I am confused....

Really appreciate some insight here..

This is what I have now:

// Request Info and Ready For Display
// First, get the artist from the loop
	$artist = str_replace(' ', '+', $artist);
						
// Now, get the info ready to extract what we need 
	$LinkPrep = "http://api.site.com/api/3.0/search/artists.json?query={$artist}&apikey=KEYID\">";
	$array = json_decode($LinkPrep, true);
	print_r($array);
	$Link = "<a target='_blank' class='tipsheet' href='$array['resultsPage']['results']['artist'][0]['uri']'><img src='images/skLogoBlack.jpg' height='25' border='0'></a>";

I am probably way off here...

I guess the main question is, should I parse all of the data and extract the links for each artist in the loop or do I parse them after the specific artist link is chosen. The latter makes more sense to me but how do I do this? Once the link is clicked, how do I handle the XML and uri redirection?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.