简体   繁体   中英

Google Apps Script oAuth onOpen authorization

I'm using a Google spreadsheet as a template that is copied at form submission. This spreadsheet has several custom functions.

I've run into two problems on spreadsheets copied from the template:

  1. A custom menu function that allows the user to create a PDF of the active sheet cannot be authorized from the front end -- it simply hangs. It appears oAuth authorization can only occur from the code editor, which I can't expect users to do.

  2. Users will click a custom menu function, get the authorization dialog, authorize, then forget to click again to run the function.

Is there a way to have users authorize all functions, including oAuth (for PDF creation), as soon as they open the sheet?

Just in case someone else happens upon this, I think I found my answer:

It appears that functions using oAuth can't be authorized from the front-end. It also appears that Google has no intention of making it available in the future unless you want to write your own authorization flow. I, for one, do not.

I did, however, find a work-around. By including the functions that need authorization in a library and including that library in your script, users only need to authorize a function once, no matter how many spreadsheets call the function.

There are only 12 users in my organization, so I got off easy on this one -- I can go to each of their computers and authorize the functions in the library once, and that's that.

Hope this helps someone!

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