May 4, 201214 yr I'm performing a search of the Google Books API and I'm trying to use the individual pieces of data it sends back but I'm not too sure how really... Here's what I have so far... isbn = $_POST['isbn']; $url = "https://www.googleapis.com/books/v1/volumes?q=isbn:" . $isbn . "&key={API Key}"; $test1 = file_get_contents($url); echo "<pre>"; print_r ($test1); echo "</pre>"; This performs the search and returns this information https://www.googleapis.com/books/v1/volumes?q=isbn:1604502428 but in my site. How do I take the individual parts such as the name of the author? I've tried using simpleXML_load_string but I couldn't get it to work, not too sure if I was even doing it right tbh
May 4, 201214 yr looks like it returns JSON to me, so you need to pass it through a json parser to decode it to native array format. $data = json_decode($test1); print_r($data);
May 5, 201214 yr Author this managed to do it $obj = json_decode($test1, true); echo $obj['items']['0']['volumeInfo']['title']; thanks
May 7, 201214 yr Author As Jock says, Print_r - solves soooo many issues in PHP when it comes to outputting data. I knew how to view the data using print_r, I just couldn't isolate the individual parts, managed it now though
Create an account or sign in to comment