You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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();
The text was updated successfully, but these errors were encountered:
Sagar-AArya
changed the title
Get workspace files along with sharing information
Get workspace drive files along with sharing information
Jan 21, 2025
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.
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.
The text was updated successfully, but these errors were encountered: