Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

176
Vistas
How do I delete files from a shared folder using Google Drive V3?

I'm trying to build a feature that deletes old files in a shared Google drive folder as follows:

private async deleteExpiredFiles(
  dataType: DataType,
  folderId: string,
  expirationDate: string,
): Promise<void> {
  const {
    data: { files: filesToDelete },
  } = await this.drive.files.list({
    q: `'${folderId}' in parents and createdTime <= '${expirationDate}'`,
    supportsAllDrives: true,         
    includeItemsFromAllDrives: true,
  });

  if (!filesToDelete) {
    return;
  }

  await Promise.all(
    filesToDelete.map(async (file) => {
      if (!file.id) {
        return;
      }

    const permissionIds = await this.drive.permissions.list({
      fileId: file.id,
        supportsAllDrives: true,
      });

      if (!permissionIds.data.permissions) {
        return;
      }

      Promise.all(
        permissionIds.data.permissions.map(async (permission) => {
          if (!permission.id || !file.id) {
            return;
          }

          await this.drive.permissions.delete({
            fileId: file.id,
            permissionId: permission.id,
            supportsAllDrives: true,
          });
        }),
      );
    }),
  );
}

I have set up all the permission in the Google Drive folder as well as get the correct credentials for the service account. However when I try to run this, I get the following error: GaxiosError: The authenticated user does not have the required access to delete the permission.

I can use drive.files.list fine and see the files as well as list the permission ids. But it isn't letting me delete them. Any advice?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Solved!

Rather than permanent deleting the files. I simply move them to the trash wth the following code:

await this.drive.files.update({
          fileId: file.id,
          requestBody: { trashed: true },
          supportsAllDrives: true,
        });
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda