22976 Posts in 11702 Topics by 2826 members
|Go to End|
3 July 2012 at 8:52am
I would like to format and display the results for an app from the iTunes search API as a page on my site. I am sure many of you veterans are now saying, oh how simple, but I myself am not sure where to begin. Here is an example search:
As you can see, you get JSON formatted data with all kinds of useful information including links to artwork which I would like to display as images on my page. It's pretty cool, the API search documentation is here:
So basically, how do I retrieve the JSON info from the URL and use the data provided in SS? I am using 2.4.5.
Thanks for any pointers!!!
3 July 2012 at 9:49pm
$service = new RestfulService("http://itunes.apple.com/");
$response = $service->request("lookup?id=422876559");
The important line is json_decode($response->getBody()); This converts the JSON to an array when you can then use to pass data back to the template or doing other things with.
4 July 2012 at 11:30am
Oh wow! That's cool! I am going to try this out thank you so much!
p.s. I had read about caching on the Apple website to increase response time (and of course not overload their servers), but I did not even want to address it in this question....figured I would in the least start out trying to get data I could use. Turns out you answered it anyway! Thanks for this informative and thorough response.
5 July 2012 at 7:05pm
See http://api.silverstripe.org/2.4/sapphire/integration/RestfulService.html for all the options you can configure but RestFulService out of the box will cache your data for an hour. You can customize this period in the contstructor.
|Go to Top|