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

226
Vistas
Can't authenticate youtube api client with access token

My backend generates the access_token with below redirect controller:

const logged = async (req: Request, res: Response) => {
  const code = (req.query.code as string) || null;
  const state = (req.query.state as string) || null;
  const error = (req.query.error as string) || null;

  const oauth2Client = new youtube.auth.OAuth2(
    GOOGLE_CLIENT_ID,
    GOOGLE_SECRET,
    GOOGLE_REDIRECT_URI,
  );

  const { tokens: { access_token }} = await oauth2Client.getToken(code);
  res.send({ access_token });
};

Returned code is similar to: "ya29.<MUCH_MORE_CHARACTERS_HERE>_BtA0163"

Then somewhere else I'm trying to create a client with this access token like this:

const youtube = require("@googleapis/youtube");
const youtubeApi = youtube.youtube({
  version: "v3",
  auth: "ya29.<MUCH_MORE_CHARACTERS_HERE>_BtA0163",
});

(Btw I'm aware that I could get the client on the redirect controller. I just don't want to)

But everytime I try to access something, it gives me error:

  code: 400,
  errors: [
    {
      message: 'API key not valid. Please pass a valid API key.',
      domain: 'global',
      reason: 'badRequest'
    }
  ]
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I believe your goal is as follows.

  • You want to use your access token to the client with googleapis for Node.js.

In your script, how about the following modification?

From:

const youtube = require("@googleapis/youtube");
const youtubeApi = youtube.youtube({
  version: "v3",
  auth: "ya29.<MUCH_MORE_CHARACTERS_HERE>_BtA0163",
});

To:

const { google } = require("googleapis");
const auth = new google.auth.OAuth2();
auth.setCredentials({ access_token: "ya29.<MUCH_MORE_CHARACTERS_HERE>_BtA0163" });
const youtubeApi = google.youtube({ version: "v3", auth });
about 4 years ago · Juan Pablo Isaza Denunciar
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