简体   繁体   中英

Google apps script permission to access a folder

This simple code works in a standalone script and also in a script bound to a google sheet if i run directly the function, but get a permission error when i run it opening the sheet. Where is the problem?

function onOpen() {
  jsondir = DriveApp.getFolderById("XXXXXXXXXXXXXXXXXXXXXXXXXXXX")
  Logger.log(jsondir)
}

In the case of use of method (DriveApp) which is required the authorization, the function has to be installed as a trigger. How to install the trigger is as follows. The detail information is here .

  • On the script editor.
    • Edit -> Current project's triggers
    • Click "No triggers set up. Click here to add one now."
    • At "Run", select "onOpen"
    • At Events, select "From spreadsheet" and "On open"
    • Push "Save" button.

If I misunderstand your question, I'm sorry.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM