Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get workspace drive files along with sharing information #3603

Open
Sagar-AArya opened this issue Jan 21, 2025 · 0 comments
Open

Get workspace drive files along with sharing information #3603

Sagar-AArya opened this issue Jan 21, 2025 · 0 comments

Comments

@Sagar-AArya
Copy link

Sagar-AArya commented 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.

  1. Create a service account.
  2. Add the service account in domain-wide-delegated list.
  3. 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();
@Sagar-AArya Sagar-AArya changed the title Get workspace files along with sharing information Get workspace drive files along with sharing information Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant