I am trying to upload a video to YouTube using Node.js, but I keep encountering a "Login Required" error consistently. I have confirmed that I have the access token correctly as I can log it in my console. Below is the complete code for performing the upload operation. The code includes the necessary context for understanding the issue.
exports.acceptSubmit = async (req, res) => { try { const notificationId = req.params.notificationId; // Find the notification by ID const notification = await Notification.findById(notificationId); if (!notification) { return res.status(404).json({ message: "Notification not found." }); } // Get the creator's user ID from the notification const creatorId = notification.creatorId; // Find the creator based on creatorId const creator = await User.findById(creatorId); if (!creator) { return res.status(404).json({ message: "Creator not found." }); } // Get the creator's access token console.log(creator); const accessToken = creator.accessToken; const pendingVideo = await PendingVideo.findById(notification.videoId); if (!pendingVideo) { return res.status(404).json({ message: "Pending video not found." }); } const videoTitle = pendingVideo.title; const videoDescription = pendingVideo.description; const videoUrl = pendingVideo.videoUrl; // Assuming this is the S3 URL const thumbnailUrl = pendingVideo.thumbnailUrl; // Assuming this is the S3 URL for thumbnail // authenticate with the YouTube Data API using the creator's access token const youtube = google.youtube({ version: 'v3', auth: accessToken, }); const videoResponse = await youtube.videos.insert({ part: 'snippet,status', requestBody: { snippet: { title: videoTitle, description: videoDescription, }, status: { privacyStatus: 'public', // or 'private' or 'unlisted' }, }, media: { mimeType: 'video/*', body: s3.getObject({ Bucket: 'editingfiles', Key: 'videos/1693044658221-Course_selling_done.mp4', }).createReadStream(), }, }); // get the uploaded video's ID const videoId = videoResponse.data.id; // upload the thumbnail const thumbnailResponse = await youtube.thumbnails.set({ videoId: videoId, media: { mimeType: 'image/jpeg', // or 'image/png' body: s3.getObject({ Bucket: 'editingfiles', Key: 'thumbnails/1693044658221-server code.png', }).createReadStream(), }, }); return res.json("all good"); } catch (error) { console.error(error); res.status(500).json({ message: "Server error." }); }};I have attempted to regenerate the token, but I continue to receive the same error. I am expecting the code to successfully upload the video to YouTube using the provided access token.ErrorGaxiosError: Login Required.Any insights into why I might be encountering the "Login Required" error would be greatly appreciated.