从自己的驱动器访问文件时如何使用较窄的Google Apps脚本授权范围 [英] How to use narrower Google Apps Script Authorization Scope when accessing file from own drive

查看:104
本文介绍了从自己的驱动器访问文件时如何使用较窄的Google Apps脚本授权范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个Google表格插件,并使用以下方法将模板表格从Google驱动器复制到用户当前的Google电子表格中:

I'm making a google sheets addon and I copy a template sheet from my google drive to the user's current google spreadsheet using:

let ss = SpreadsheetApp.getActive(); 
let source = SpreadsheetApp.openById(TemplateSpreadsheetId); //  <-- gets scope error
let newSheet = source.getSheetByName(mainSheetName).copyTo(ss);

当我指定范围 https://www.googleapis.com/auth/spreadsheets 时,此方法有效a>,但有没有办法使用较窄的Google Apps脚本授权范围?除此之外,我只需要@OnlyCurrentDoc或

It works when I specify scope https://www.googleapis.com/auth/spreadsheets" in appsscript.json, but is there a way to use a narrower Google Apps Script Authorization Scope ? Other than this I only need @OnlyCurrentDoc or https://www.googleapis.com/auth/spreadsheets.currentonly"

之所以如此重要,是因为用户必须同意我的插件可以查看,编辑,创建和删除Google云端硬盘中的电子表格",这听起来有点吓人我.

The reason this matters it that users will have to agree that my addon can "See, edit, create, and delete your spreadsheets in Google Drive", which sounds like kind of scary permissions to me.

推荐答案

根据 https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app#openbyidid

授权
使用此方法的脚本需要使用以下一项或多项授权 以下范围:

Authorization
Scripts that use this method require authorization with one or more of the following scopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

我认为...仅当id是脚本容器之一时,... currentonly范围才起作用

I think that the ...currentonly scope only will work when the id is the one of the script container

这篇关于从自己的驱动器访问文件时如何使用较窄的Google Apps脚本授权范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆