How to programmatically remove my access to a shared Google Drive file when I am not the owner?

Context:

I am trying to use the Google Drive API to remove my own access to files that have been shared with me. My goal is to stop having access to these files entirely. I am not the owner of these files, but I have been added as a collaborator (either as an editor, viewer, or commenter).

What I’ve Tried:

I’ve written a script using Google Apps Script that attempts to remove my permissions using the permissions.delete method from the Google Drive API. Here’s the relevant portion of the script:

function removeMyselfFromAllFiles() {
  const activeUserEmail = Session.getActiveUser().getEmail();
  var pageToken = null;

  do {
    var result = Drive.Files.list({
      q: "trashed = false", 
      pageSize: 100,         
      pageToken: pageToken,  
      corpora: "allDrives",  
      includeItemsFromAllDrives: true,
      supportsAllDrives: true, 
      fields: "nextPageToken, files(id, name, permissions)"
    });

    if (result.files && result.files.length > 0) {
      var files = result.files;

      for (var i = 0; i < files.length; i++) {
        var file = files[i];

        for (var j = 0; j < file.permissions.length; j++) {
          var permission = file.permissions[j];
          if (permission.emailAddress === activeUserEmail) {
            var url = 'https://www.googleapis.com/drive/v3/files/' + file.id + '/permissions/' + permission.id;
            var response = UrlFetchApp.fetch(url, {
              method: 'delete',
              headers: {
                Authorization: 'Bearer ' + ScriptApp.getOAuthToken()
              },
              muteHttpExceptions: true
            });

            if (response.getResponseCode() === 204) {
              Logger.log("Successfully removed myself from: " + file.name);
            } else {
              Logger.log("Failed to remove myself from: " + file.name + " - Response: " + response.getContentText());
            }
          }
        }
      }
    }
    pageToken = result.nextPageToken;

  } while (pageToken);
}

The Problem:

When running the script, I often encounter the following error:

Failed to remove myself from: [File Name] - Response: {
  "error": {
    "code": 403,
    "message": "The user does not have sufficient permissions for this file.",
    "errors": [
      {
        "message": "The user does not have sufficient permissions for this file.",
        "domain": "global",
        "reason": "insufficientFilePermissions"
      }
    ]
  }
}

I understand that the error occurs because I don’t have sufficient permissions to modify the sharing settings of the file. However, my goal is simply to remove my access to the file so that it no longer appears in my Google Drive, and neither my email appears as a collaborator on the file.

My Questions:

  1. Is there a way to programmatically remove my access to a file when I am not the owner, using the Google Drive API?
  2. If not, are there any alternative approaches I could take to achieve the same goal (stopping access to the file) through the API or any other method?
  3. Could there be a different API method or strategy that I should be using instead?

Additional Context:

  • I want to automate the process for multiple files and avoid manually changing permissions on each one.
  • I’m looking for a scalable solution that can handle many files automatically without manual intervention.

Any help or guidance on how to achieve this would be greatly appreciated!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật