Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.1K
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!