可以在未经完全许可的情况下更新表单的电子表格(Google 应用程序脚本)
Possible To Update a Form's Spreadsheet Without Full Permission (Google App Scripts)
有没有办法edit/manipulate一个Google Form's destination Spreadsheet without giving the app script full Spreadsheet privileges?我不认为这是可能的,但在启用某些首选项时,下面的屏幕截图似乎暗示这是可能的(至少对我而言)。
我知道如何做到这一点的唯一方法是 spreadsheet.OpenByID
结合 destinationID property。
/**
* @OnlyCurrentDoc
*/
//Constants
const thisForm = FormApp.getActiveForm();
const theSpreadsheetForTheForm = SpreadsheetApp.openById(thisForm.getDestinationId());
然而,当我授权和运行时,由于权限不足而失败。参数。
如果不删除 @OnlyCurrentDoc 语句(并因此授予对驱动器中所有传播sheet 的访问权限)。
由于脚本未安装在您的传播中sheet(它安装在表单中),它将无法访问 sheet。
不,如果没有电子表格的完整授权范围,这是不可能的。您可以通过在清单中显式提供授权范围然后 运行 下面的测试函数(在具有设置目标的表单的上下文中)来亲眼看到:
{
"oauthScopes": [
"https://www.googleapis.com/auth/spreadsheets.currentonly",
"https://www.googleapis.com/auth/forms.currentonly"
]
}
const checkDestinationAccess = () => {
try {
SpreadsheetApp.openById(FormApp.getActiveForm().getDestinationId());
}
catch (error) {
console.log(`Expected spreadsheet to open, got error instead: ${error}`);
}
};
您的怀疑应该得到证实,只有 https://www.googleapis.com/auth/spreadsheets
会有所帮助:
Expected spreadsheet to open, got error instead: Exception: You do not have permission to call SpreadsheetApp.openById. Required permissions: https://www.googleapis.com/auth/spreadsheets
有没有办法edit/manipulate一个Google Form's destination Spreadsheet without giving the app script full Spreadsheet privileges?我不认为这是可能的,但在启用某些首选项时,下面的屏幕截图似乎暗示这是可能的(至少对我而言)。
我知道如何做到这一点的唯一方法是 spreadsheet.OpenByID
结合 destinationID property。
/**
* @OnlyCurrentDoc
*/
//Constants
const thisForm = FormApp.getActiveForm();
const theSpreadsheetForTheForm = SpreadsheetApp.openById(thisForm.getDestinationId());
然而,当我授权和运行时,由于权限不足而失败。参数。
如果不删除 @OnlyCurrentDoc 语句(并因此授予对驱动器中所有传播sheet 的访问权限)。
由于脚本未安装在您的传播中sheet(它安装在表单中),它将无法访问 sheet。
不,如果没有电子表格的完整授权范围,这是不可能的。您可以通过在清单中显式提供授权范围然后 运行 下面的测试函数(在具有设置目标的表单的上下文中)来亲眼看到:
{
"oauthScopes": [
"https://www.googleapis.com/auth/spreadsheets.currentonly",
"https://www.googleapis.com/auth/forms.currentonly"
]
}
const checkDestinationAccess = () => {
try {
SpreadsheetApp.openById(FormApp.getActiveForm().getDestinationId());
}
catch (error) {
console.log(`Expected spreadsheet to open, got error instead: ${error}`);
}
};
您的怀疑应该得到证实,只有 https://www.googleapis.com/auth/spreadsheets
会有所帮助:
Expected spreadsheet to open, got error instead: Exception: You do not have permission to call SpreadsheetApp.openById. Required permissions: https://www.googleapis.com/auth/spreadsheets