DriveApp Access Denied

Viewed 3143

I have a Google Script attached to a Form that does a whole bunch of different things, but ultimately creates a couple of copies of a sheet.

The process has been working great for months, but recently I have been getting the following error when using the File.makeCopy method (https://developers.google.com/apps-script/reference/drive/file#makecopyname-destination)

 function createTest()
{
  var templateFile = DriveApp.getFileById("ID");
  templateFile.makeCopy("NAME", DriveApp.getFoldersByName("FOLDERNAME").next())
}

Access Denied: Drive App (on the templateFile.makeCopy line)

I have ensured that the Drive scope is added and there are no GSuite settings that could cause this(such as the DriveApp being disabled).

I cannot find a good answer as to why this would have stopped working over the last few days. Any ideas are welcome!

1 Answers

I don't know if this is still relevant, but as I had the exact same issue without an answer, I happened to use a wrong file id. So if you run this code, be sure to double check the accessed id(s).

Also: make sure the folder iterator in DriveApp.getFoldersByName("FOLDERNAME").next() actually has a next, thus there is a folder called "FOLDERNAME" inside your root folder. Else you would make a call on an undefined object.

Related