0

In the file sharing settings in Google Drive, there is an option to set that users defined as viewers or commenters will not be able to download the file,

Is it possible to change this setting using Google Apps Script or Drive API?

I looked for information about the in the Google documentation here:

  1. https://developers.google.com/apps-script/reference/drive/drive-app?hl=en 2.https://developers.google.com/drive/api/v2/reference/permissions But I didn't find any suitable information.
abaye
  • 1
  • 2
  • From your showing script, I guessed that you might have copied this sample script in this thread. https://stackoverflow.com/q/63664349 If my understanding is correct, in the case of your showing script, the required scope is not used and it is not mentioned about Drive API. Please be careful about this. And, I flagged it as a duplicate question of this thread. – Tanaike Apr 18 '23 at 00:39

1 Answers1

0

apparently the writing influenced me to find the answer:

function myFunction() {
   let fileId = "1VITtMtOqcJeBOzstCS2wPDuRXP5d2d5h" // Please set the file ID.
   let url = "https://www.googleapis.com/drive/v3/files/" + fileId;
   let res = UrlFetchApp.fetch(url, {
     method: "patch",
     headers: {authorization: "Bearer " + ScriptApp.getOAuthToken()},
     contentType: "application/json",
     payload: JSON.stringify({viewersCanCopyContent: false, writersCanShare: false}),
   });
   Logger.log(res.getContentText())
}

viewersCanCopyContent = Sets the download limit for viewers and commenters

writersCanShare = defines the sharing limit by editors

abaye
  • 1
  • 2