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

1.1K
Visualizações
Error: No access, refresh token or API key is set. Google Youtube API V3

I am going to get my subscription list with the help of the YouTube api. I wrote this piece of code.

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


const oauth2 = google.oauth2('v2');
const express = require('express')
const app = express()
const port = 3000


const oauth2Client = new google.auth.OAuth2(
    "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "xxxxxxxxxxxxxxxxxxxxxxx",
    "http://localhost:3000/auth/google/callback"
);

google.options({
    auth: oauth2Client
});

// generate a url that asks permissions for Blogger and Google Calendar scopes
const scopes = [
  'https://www.googleapis.com/auth/youtube',
  'https://www.googleapis.com/auth/youtube.channel-memberships.creator'
];

const url = oauth2Client.generateAuthUrl({
  // 'online' (default) or 'offline' (gets refresh_token)
  access_type: 'offline',

  // If you only need one scope you can pass it as a string
  scope: scopes
});

app.get('/',(req,res,next)=>{
    res.send(url);
})
let tok = "";
app.get('/auth/google/callback',(req,res,next)=>{
    res.send('Susses Authrations');
    console.log("Code authrations : "+req.query.code);
     const {tokens} = oauth2Client.getToken(req.query.code)
     oauth2Client.setCredentials(tokens);
     oauth2Client.on('tokens', (tokens) => {
        if (tokens.refresh_token) {
          // store the refresh_token in my database!
          console.log("refresh_token : "+ tokens.refresh_token);
          tok =  tokens.access_token;
        }
        console.log("Assess Token : "+ tokens.access_token);
      });
})

app.get('/youtube',(req,res,next)=>{
    const youtube = google.youtube('v3',{
        'access_token':oauth2Client.credentials.access_token,
        'refresh_token':oauth2Client.credentials.refresh_token,
        'api_key':oauth2Client.credentials.api_key
    });

    youtube.channels.list({
        "part": [
          "snippet,contentDetails,statistics"
        ],
        "id": [
          "UC_x5XG1OV2P6uZZ5FSM9Ttw"
        ]
      }).then(e=>{
        console.log(e.request)
    })
   

})


app.listen(port,()=>{
    console.log("Hello World")
});

But unfortunately I encounter an error (Error: No access, refresh token or API key is set.) Which apparently does not recognize my refresh token. I am a novice and thank you for guiding me. I also use the clinet id and clinet secret I also built a console inside Google and activated YouTube related libraries.

over 4 years ago · Santiago Trujillo
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