Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

144
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda