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

141
Visualizações
googleapis library, multiple requests handle

I'm trying to figure out how to use 'googleapis' library with a lot of requests.

Initialize oauth2Client using 'googleapis' library

const {google} = require('googleapis');

const oauth2Client = new google.auth.OAuth2(
  YOUR_CLIENT_ID,
  YOUR_CLIENT_SECRET,
  YOUR_REDIRECT_URL
);

Everything goes fine, then I take the refresh_token and save it somewhere in the database. Now with each user request, I need to somehow get the oauth2Client instance or create a new one via new(like from above) and pass the saved refresh_token via setCredentials

oauth2Client.setCredentials({
    refresh_token: savedToken
});

in this case, a new access_token will be generated on every request, anyway now I can use library API to create requests by passing oauth2Client

const oauth2 = google.oauth2({
    version: 'v2',
    auth: oauth2Client
})

Well, first of all, is it normal to do this? When using an already created (one instance), I'm afraid something may not work correctly and the request will be made with a different token.

and also with each request, since I pass the refresh_token, a new access_token will be created, which I also wanted to avoid.

It is desirable that I can use this library, and that the token is not refreshed with each request.

or maybe it's better to create a class in which I make requests myself, something like, but in this case i need to control and refresh token manualy

   class DocsGoogle {
      ...
      getAll () {
         // make HTTP request with tokens what needs and return 
      }
      ...
   } 

How is best to do this?

about 4 years ago · Juan Pablo Isaza
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