flutterdarthttpgoogle-books-api

Google Books API not returning the same as displayed on browser (Flutter)


I am building a book app with Flutter for Android and iOS. I am using Google Books API to retrieve book data, but I have noticed something strange which I dont understand. If we look at the book data displayed in chrome browser (https://www.googleapis.com/books/v1/volumes/b3GuDwAAQBAJ), we can see that the content (eg. field categories) is different than what I get when calling http response and printing out it's body. In addition to that, it also seems like unicode characters (eg. from description) are not sent.

Data displayed on the browser

The obtained Response body

The code that I'm using to get the API data can be seen below:

Response result = await http.get(Uri.parse(url), headers: {'content-type': 'application/json; charset=utf-8'});
if (result.statusCode == 200) {
  final jsonResponse = jsonDecode(utf8.decode(result.bodyBytes));
  if (jsonResponse["totalItems"] == 0) {
    return List.empty();
  }

  //this prints out the content in above image
  print(result.body.toString());

  final booksMap = jsonResponse['items'];
  List<dynamic> books = booksMap.map((i) => Book.fromJson(i)).toList();
  return books;

Solution

  • It seems that https://www.googleapis.com/books/v1/volumes/b3GuDwAAQBAJ gives different data than your usual search query (eg. https://www.googleapis.com/books/v1/volumes?q=isbn:9780143123231). I do not know the reason why.