I am using the 'googleapis' library in NodeJS and I am trying to return the list of files and folders in the currently specified folder, but instead I find drive.files.list
returns all files that the user has been granted permissions to read.
My goal is to be able to download the folder structure below a given folder, that then could be consumed by the NodeJS application in a meaningful way.
The code I am using is as follows:
const fs = require('fs');
const google = require('googleapis');
const OAuth2 = google.auth.OAuth2;
const key = require('./key.json');
const jwtClient = new google.auth.JWT(
key.client_email,
null,
key.private_key,
['https://www.googleapis.com/auth/drive'],
null
);
const drive = google.drive({
version: 'v3',
auth: jwtClient
});
jwtClient.authorize(function (err, tokens) {
if (err) {
console.log(err);
return;
}
// Make an authorized request to list Drive files.
drive.files.list({
includeRemoved: false,
spaces: 'drive',
fileId: 'the-file-id-of-the-folder'
}, function (err, resp) {
if (!err) {
var i;
var files = resp.files;
for (i=0; i<files.length; i++) {
if (files[i].mimeType !== 'application/vnd.google-apps.folder') {
console.log('file: ' + files[i].name);
} else {
console.log('directory: ' + files[i].name);
}
console.log(files[i]);
}
} else {
console.log('error: ', err);
}
});
});
Note I did try the drive.files.get
endpoint, without the alt: 'media'
parameter, but it does not seem to return any more metadata that the drive.files.list
call.