So I use Google Books API in my application, and i make a request do display data in console, but for some reason it returns an empty object, instead of array of books.
Javascript code:
const API_KEY = 'key=<API-KEY>';
const BASE_URL = 'https://www.googleapis.com/books/v1/';
const API_URL = BASE_URL + 'volumes?q=subject:fiction' + API_KEY;
getBooks(API_URL);
function getBooks(url){
fetch(url).then(res => res.json()).then(data =>{
console.log(data);
})
}
Console in browser:
Edit: So I added '&' in the url and it changed, but now it gives 403 error:
{
"error": {
"code": 403,
"message": "Requests from this Android client application \u003cempty\u003e are blocked.",
"errors": [
{
"message": "Requests from this Android client application \u003cempty\u003e are blocked.",
"domain": "global",
"reason": "forbidden"
}
],
"status": "PERMISSION_DENIED"
}
}
Maybe I got the wrong key? I got it from Google Books credentials, so I thought it should've worked.
You forgot the & sign between the query params, so you need to change
const API_URL = BASE_URL + 'volumes?q=subject:fiction' + API_KEY;
to
const API_URL = BASE_URL + 'volumes?q=subject:fiction&' + API_KEY;
And also revoke this API Key
You sent the key as part of the q value because you forgot an '&'.
const API_URL = BASE_URL + 'volumes?q=subject:fiction&' + API_KEY;