I am writing a Google Workspace add-on where the script creates one Google Document for each line in a Google Sheet owned by the user. The Google Documents are saved in the root of the user's Google Drive. I want the script to be able to automatically move all the files to a folder chosen by the user (or to create the files directly in a specified folder). I don't want the script to access the other user's files.
This only works if I add the scope, whereas
.file
is enough to create the new files in the root folder.
Is there a way to do what I want without using ?
I am writing a Google Workspace add-on where the script creates one Google Document for each line in a Google Sheet owned by the user. The Google Documents are saved in the root of the user's Google Drive. I want the script to be able to automatically move all the files to a folder chosen by the user (or to create the files directly in a specified folder). I don't want the script to access the other user's files.
This only works if I add the https://www.googleapis/auth/drive
scope, whereas https://www.googleapis/auth/drive.file
is enough to create the new files in the root folder.
Is there a way to do what I want without using https://www.googleapis/auth/drive
?
- Looks like moveTo(destination) requires the scope that ends in drive – Cooper Commented Feb 1 at 18:36
- I was hoping to find a way to write to Drive (or move files created by the script) without being able to read other files, to ensure the privacy of the user. – François Talbot Commented Feb 1 at 20:59
1 Answer
Reset to default 3You may be able do this with google-picker and making user choose the folder they want, using scope:
https://www.googleapis/auth/drive.file
See https://developers.google/apps-script/guides/dialogs#file-open_dialogs
Alternatively, You may try creating the folder yourself and then try moving the file there using inbuilt methods or if inbuilt methods throw an error, then by accessing the respective apis.