Maintaining enabled APIs in Container-bound Script for a Google Sheet Template

家住魔仙堡 提交于 2020-01-05 09:04:26

问题


I have a Google sheet with a Container-bound Script that makes Google Classroom API calls. I have added the spreadsheet now as a template for all teachers in my organization to copy the sheet and use it for themselves.

However, when teachers copy from the template, a new project is created in Google Console with no enabled APIs for that new project. They would have to go into the developer console and enable Classroom API for it to work....

No! This is way too much of a hassle for my fellow teachers! There has to be a better way. What am I doing wrong? How can my script keep the API calls enabled for all copies of the spreadsheet? Do I need to publish my script in a particular way or set up my project in a particular way? Whats the right approach here, guys?

This error when using the script in a copied spreadsheet. But of course, works fine in the original template file.

Google Classroom API has not been used in project project-id-xxxxxxxxxxxxxxx before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/classroom.googleapis.com/overview?project=project-id-xxxxxxxxxxxxxxxx then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.


回答1:


You should publish your script as Sheets Add-on: https://developers.google.com/apps-script/add-ons/

This gives you next benefits:

  1. when spreadsheet (with enabled add-on) is copied, there's no need to manually enable APIs, they are stay enabled;
  2. when you update code of your add-on, it is automatically updated for all spreadsheets where it was enabled, so you don't have to copy your changes manually.


来源:https://stackoverflow.com/questions/47604982/maintaining-enabled-apis-in-container-bound-script-for-a-google-sheet-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!