代码之家  ›  专栏  ›  技术社区  ›  PGSystemTester

可以在没有完全许可的情况下更新表单的电子表格(Google应用程序脚本)

  •  0
  • PGSystemTester  · 技术社区  · 4 年前

    Google Form 的目标电子表格,而不提供应用程序脚本 full Spreadsheet privileges

    enter image description here

    我知道的唯一方法就是 spreadsheet.OpenByID 结合 destinationID property .

    /**
     * @OnlyCurrentDoc
     */
    
    //Constants
      const thisForm = FormApp.getActiveForm();
      const theSpreadsheetForTheForm = SpreadsheetApp.openById(thisForm.getDestinationId());
    

    但是,当我授权并运行时,由于缺少权限,它失败了。参数。

    enter image description here

    0 回复  |  直到 4 年前
        1
  •  2
  •   mary    4 年前

    除非删除@OnlyCurrentDoc语句(因此,授予对驱动器中所有电子表格的访问权限)。

    因为脚本没有安装在电子表格中(它安装在表单中),所以它将无法访问工作表。

        2
  •  1
  •   Oleg Valter is with Ukraine    4 年前

    不,没有电子表格的完全授权范围,这是不可能的。通过在清单中显式提供授权作用域,然后运行下面的测试函数(在具有set destination的表单上下文中),您可以自己查看:

    {
      "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

    应打开电子表格,但出现错误:异常:您没有调用的权限电子表格app.openById. 所需权限: https://www.googleapis.com/auth/spreadsheets