0

I am trying to write a node.js script to retrieve all youtube videos uploaded on a user's channel. Such as getting the video id, title, description, thumbnail, etc...

I know this would be alot of requests, so if I hit my request limit per minute for example, I'm fine with just setting it to wait/sleep for now perhaps.

So far the script I have will work, and launch, and accept a token to begin the request, but the videos.list line always fails with this error: videos.list err = GaxiosError: No filter selected. Expected one of: id, myRating, chart

As if it wants an id (of a video/playlist?) when i am trying to just retrieve every video uploaded by a user.

full file script.js

console.log('1')
const readlineSync = require('readline-sync');
console.log('2')
const {google} = require('googleapis');
console.log('3')

//make google cloud project
//add desktop token for client id
//add youtube v3 api to project library
//create api key, add to project
var YOUTUBE_API_KEY = ''
var YOUR_CLIENT_ID = `


const youtube = google.youtube({
  version: 'v3',
  auth: YOUTUBE_API_KEY
});

// Prompt the user to sign in to Google and get an access token
console.log('Please go to the following URL to sign in to Google:');
console.log(`https://accounts.google.com/o/oauth2/auth?client_id=${YOUR_CLIENT_ID}&response_type=code&scope=https://www.googleapis.com/auth/youtube.readonly&redirect_uri=http://localhost:3000/oauth2callback`);
const accessToken = readlineSync.question('Enter the access token: ');

// Use the access token to make a request to the YouTube API
youtube.videos.list({
  part: 'id,snippet',
  mine: true
}, (err, res) => {
  if (err) {
    console.error('videos.list err = ', err);
    return;
  }
  console.log('got correctly ')

  // Print the IDs and thumbnails of the videos in the user's channel
  for (const video of res.data.items) {
    console.log(`Video ID: ${video.id}`);
    console.log(`Video thumbnail: ${video.snippet.thumbnails.default.url}`);
  }
});
Martin
  • 1,336
  • 4
  • 32
  • 69
  • `mine` isn't a parameter of [YouTube Data API v3](https://developers.google.com/youtube/v3) [Videos: list](https://developers.google.com/youtube/v3/docs/videos/list) endpoint. [My answer](https://stackoverflow.com/a/74579030) on another similar StackOverflow question solves your problem. – Benjamin Loison Dec 13 '22 at 11:45
  • I see your python solution, but I'm trying to write a solution with node.js / javascript, so i can eventually add the logic into my javascript app. I tried removing the 'mine' parameter but am still getting errors. – Martin Dec 28 '22 at 01:47
  • @Martin you have you get all the uploaded playlist of a user's channel - see [this answer](https://stackoverflow.com/a/71161121/12511801). With that playlist_id, use `playlistItems.list` for get the videos inside this playlist - [check this sample](https://developers.google.com/youtube/v3/docs/playlistItems/list?apix_params=%7B%22part%22%3A%5B%22id%2Csnippet%2CcontentDetails%2Cstatus%22%5D%2C%22maxResults%22%3A50%2C%22playlistId%22%3A%22UUaY_-ksFSQtTGk0y1HA_3YQ%22%7D). – Marco Aurelio Fernandez Reyes Dec 29 '22 at 16:53

0 Answers0