I am working on a spreadsheet add-on that deals with sending mail with attachments and merging spreadsheet data into documents. I previously used the auth/drive scope because I use DriveApp.getFileById(thisFileId).getBlob() and also .makeCopy(SaveAsName).getId() in the add-on.
I am trying to limit my scope away from restricted auth/drive scope to the recommended auth/drive.file scope. I may be completely off on my reading of the auth/drive.file scope. My understanding is the per-file access to files created or opened by the app is granted when the user selects a file with the file picker. I would assume then that a drive file the user picks could then be opened by DriveApp.getFileById(thisFileId), but I am getting a permission error that I need (auth/drive or auth/drive.readonly) in order to do this. What file authorization is granted when using this scope?
It could be that I am missing something on the picker file integration. I have it working basically using the developer example here (https://developers.google.com/apps-script/guides/dialogs#file-open_dialogs). I also can not use the DriveApp.getRootFolder(); in the getOAuthToken() function because it also says I need the auth/drive or auth/drive.readonly scope.
I guess the other option is to use the auth/drive.readonly scope which is sensitive, but not restricted. I don’t know if this would be in addition to the auth/drive.file scope or in place of it. Am I the only one who finds it hard to figure out what they are expecting?
/** * Test Function for drive.files stuff */function testDrive() { //var copyFile = Drive.Files.copy(resource, fileId, optionalArgs); var emailObject = {}; var blobs = []; var newFileName = "New Doc Name"; var templateFileId = "1PbgbJIO7imPBFSqDSYDCKuv7GjnxuIkyyk1zopvVKmo"; var emailTo = "some...@email.com"; var emailSubject = "Drive Test Email"; var emailTextBody = "Drive test email. This should have an attachment"; var copyFileResource = Drive.Files.copy({"title": newFileName}, templateFileId); var newFileId = copyFileResource.id; var newFile = DocumentApp.openById(newFileId); // update or merge info into new file blobs.push(newFile.getBlob()); emailObject.attachments = blobs; MailApp.sendEmail(emailTo, emailSubject, emailTextBody, emailObject );}