I created an app for the members of my youtube channel, and my goal is that only the members can access it, so I'm trying to use the Youtube data API, to retrieve my members:list. So that u can have an automatic whitelist with my members. My problem is that i get a 403 error code and it says that i need permission to do this, even though i make the request by using the token i get when i connect the youtube channel account to the app using OAuth2.0.It looks like i've done everything i could and that now i just need a permission from Google or Youtube, my question is where do i get that permission?Because i haven't found anything in the documentation, so please i really need help.
const express = require('express');const { google } = require('googleapis');const { Pool } = require('pg');const path = require('path');const fs = require('fs');require('dotenv').config();const app = express();const port = process.env.PORT || 3000;// Charger les secrets client depuis un fichier localconst credentials = JSON.parse(fs.readFileSync('client_secret.json'));const { client_id, client_secret, redirect_uris } = credentials.web;// ID de la chaîne cibleconst targetChannelId = 'Here i put the ID of my channel'; // Remplacez par l'ID de votre chaîne cible// Configuration de la base de donnéesconst pool = new Pool({ connectionString: process.env.DATABASE_URL, ssl: { rejectUnauthorized: false }});// Middlewareapp.use(express.json());app.use(express.urlencoded({ extended: true }));app.use(express.static(path.join(__dirname, 'public')));// Configuration de EJSapp.set('views', path.join(__dirname, 'views'));app.set('view engine', 'ejs');// Configuration de Google OAuth2const oauth2Client = new google.auth.OAuth2( client_id, client_secret, redirect_uris[0]);// Routesapp.get('/', (req, res) => { res.render('index');});app.get('/auth', (req, res) => { const scopes = ['https://www.googleapis.com/auth/youtube.channel-memberships.creator','https://www.googleapis.com/auth/userinfo.email' ]; const url = oauth2Client.generateAuthUrl({ access_type: 'offline', scope: scopes, }); res.redirect(url);});app.get('/oauth2callback', async (req, res) => { const { code } = req.query; try { const { tokens } = await oauth2Client.getToken(code); oauth2Client.setCredentials(tokens); console.log('Tokens received:', tokens); const youtube = google.youtube({ version: 'v3', auth: oauth2Client }); const response = await youtube.members.list({ part: 'snippet', filterByMemberChannelId: targetChannelId, maxResults: 100, }); console.log('API response:', response.data); const members = response.data.items; const client = await pool.connect(); try { await client.query('TRUNCATE TABLE members'); for (const member of members) { const channelId = member.snippet.memberDetails.channelId; await client.query('INSERT INTO members (channel_id) VALUES ($1)', [channelId]); } } finally { client.release(); } res.render('members', { members }); } catch (error) { console.error('Authentication or API request failed:', error.response ? error.response.data : error.message); res.status(500).send('Authentication failed'); }});app.listen(port, () => { console.log(`Server running on port ${port}`);});