简体   繁体   中英

Goodreads API Get Reviews

I am looking to retrieve the reviews of a certain book from Goodreads API. I am relatively new in APIs.

Here is a link to the API documentation: https://www.goodreads.com/api#book.show

I have created this basic code, and it prints out Success, but no result. Data: Object Document. Here is my code:

$.get("https://www.goodreads.com/book/isbn?format=xml&key=d9xonLKxHDCI5HF1mHjbQ&isbn=9781843589501", function(data, status){
    alert("Data: " + data + "\nStatus: " + status);
});

What am I missing to be able to display the results? ap

The result being returned is in XMLFormat. You need to have something at your client side to read the XML retireved. Have a look at the below example https://api.jquery.com/jQuery.parseXML/

I used an external library called: xml2js

Here is a code snippet as to make the returned value as you would an object.

var parseString = require("xml2js").parseString;


request(options)
.then(function(data) {
  var xml = data;

  parseString(xml, { trim: true }, (err, result) => {
    if (err) //do something
    else //something else

So here, you get the data, turn it into JSON and you can act how you want with it accordingly. Though, realise that you have a callback here!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM