Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

175
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda