Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

299
Visualizações
Why my api request returns an empty object?

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:

enter image description here

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.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

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

about 4 years ago · Juan Pablo Isaza Relatório

0

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;
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda