security - Minimal Google Drive scope to select folder and move files there - Stack Overflow

admin2025-04-17  4

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.com/auth/drive scope, whereas https://www.googleapis.com/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.com/auth/drive?

Share edited Feb 4 at 0:26 TheMaster 51.3k7 gold badges73 silver badges100 bronze badges asked Feb 1 at 16:47 François TalbotFrançois Talbot 114 bronze badges 2
  • 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
Add a comment  | 

1 Answer 1

Reset to default 3

You may be able do this with google-picker and making user choose the folder they want, using scope:

https://www.googleapis.com/auth/drive.file

See https://developers.google.com/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.

转载请注明原文地址:http://anycun.com/QandA/1744823081a88107.html