-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Description
I have a requirement to get the list of files from drive which are shared in last 7 days within my company google workspace.
For example:
[file name: abc.txt
shared on: 19th Dec
shared with: Rick
shared by: Shane
role given: viewer]
I tried below steps.
- Create a service account.
- Add the service account in domain-wide-delegated list.
- Use the service account key to make files.list API.
Initially it was returning empty list. I shared few files with the service account then I am able to see those shared files but that's not my requirement.
Is it possible to achieve the requirement or do I need to use a different API?
provided the script below for reference.
const { google } = require('googleapis');
const path = require('path');
// Path to your service account key file
const SERVICE_ACCOUNT_FILE = path.join(__dirname, 'doman_wide_delegation_service_account.json');
// Scopes for accessing Google Drive
const SCOPES = ['https://www.googleapis.com/auth/drive'];
async function listDriveFiles() {
try {
// Authenticate using the service account
const auth = new google.auth.GoogleAuth({
keyFile: SERVICE_ACCOUNT_FILE,
scopes: SCOPES,
});
const drive = google.drive({ version: 'v3', auth });
// List files in Google Drive
const response = await drive.files.list({
pageSize: 10, // Adjust the number of files you want to retrieve
fields: 'nextPageToken, files(id, name)',
// corpora: "domain",
// q: "trashed = false"
includeItemsFromAllDrives: true,
supportsAllDrives: true
});
const files = response.data.files;
if (files.length) {
console.log('Files:');
files.forEach((file) => {
console.log(`${file.name} (${file.id})`);
});
} else {
console.log('No files found.');
}
} catch (error) {
console.error('Error listing files:', error.message);
}
}
listDriveFiles();
Metadata
Metadata
Assignees
Labels
No labels