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

236
Visualizações
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 Respostas
Responde à pergunta

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 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