I want to get all the transcripts for all the videos on a youtube channel. This is my code.
async function getVideoTranscripts(videoId) { try { const response = await axios.get( `https://www.googleapis.com/youtube/v3/captions?part=snippet&videoId=${videoId}&key=${process.env.YOUTUBE_API_KEY}` ); const captionIds = response.data.items.map((item) => item.id); // Step 2: Fetch transcripts for each caption const transcriptPromises = captionIds.map(async (captionId) => { try { const transcriptResponse = await axios.get( `https://www.googleapis.com/youtube/v3/captions/${captionId}&key=${process.env.YOUTUBE_API_KEY}`, { headers: { Authorization: `Bearer ${accessToken}`, }, } ); return transcriptResponse.data.body; } catch (error) { console.error( `Error fetching transcript for caption ${captionId}:`, error ); return null; } }); const transcripts = await Promise.all(transcriptPromises); return transcripts.filter((transcript) => transcript !== null); } catch (error) { console.error(`Error fetching transcripts for video ${videoId}:`, error); return []; }}However, I keep getting this error:
AxiosError {message: 'Request failed with status code 401', name: 'AxiosError', code: 'ERR_BAD_REQUEST', config: {…}, request: XMLHttpRequest, …}My API key has full permission from the console to make any request. I am not exactly sure why this is failing.