I need to get root folder id and filter folders which have root folder as their parent folder. Using Nodejs and google drive API v3 . This is my code and how I change this code to get root folderId?
const service = google.drive('v3');
service.files.list({
auth: client2,
fields: 'nextPageToken, files(id, name, webContentLink, webViewLink, mimeType, parents)'
}, (err, res) => {
if (err) {
console.error('The API returned an error.');
throw err;
}
const files = res.data.files;
if (files.length === 0) {
console.log('No files found.');
} else {
console.log('Files Found!');
for (const file of files) {
console.log(`${file.name} (${file.id})`);
}
The folder id of the root folder is "root". The file.list method has an option parameter called q which is used for searching.
service.files.list({auth: auth,
resource: { parents: [ folderId ] },
q: "'root' in parents",
fields: '*',
spaces: 'drive',
pageToken: pageToken,
}
This code is kind of a guess as i dont have the power to test node on this machine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With