复制工作表时,谷歌应用验证功能从谷歌应用脚​​本项目中丢失

时间:2017-08-08 19:12:59

标签: google-apps-script google-sheets oauth-2.0

我开发了一个谷歌应用程序脚本应用程序,它使用电子表格作为其数据库,

我将应用程序提供给客户,方法是给他们提供一个URL,以便从电子表格中复制(脚本在该电子表格中),然后他们授权并使用该副本。

最近,我的客户正在获得一个未经验证的应用程序"授权脚本之前的屏幕。所以我填写了一个用于Google验证的表单, Google验证了,但我的客户仍然获得了未经验证的屏幕...

我怀疑问题是每张工作表在复制后都会获得新的项目ID和客户端ID ,因此Google验证不适用于他们。

有没有人知道我可以验证副本的解决方案?或者是否有另一种方式将应用程序提供给人们而不需要他们制作副本,仍然每个人都应该拥有自己的脚本和电子表格?

1 个答案:

答案 0 :(得分:1)

虽然在制作副本时没有解决方案可以保留相同的项目ID,但您可以将项目发布为Web应用程序,并让Web应用程序为您创建工作表并使用该工作表来读取和写入数据。 />
这就是我所做的事情

   function getCustomSpreadsheet(){
        //try to get the spreadsheet id of the already created spreadsheet
        var ssid = PropertiesService.getUserProperties().getProperty('customSsid');
        //if sheet does not exist, create it
        if(!ssid) var ssid = createCustomSpreadsheet();
        var ss = SpreadsheetApp.openById(ssid);
        return ss;
   }

   function createCustomSpreadsheet(){
        //make a copy of your template spreadsheet and save its id to a property
        fileId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";//your ss id here
        var ss = DriveApp.getFileById(fileId).makeCopy();
        var ssid = ss.getId();
        PropertiesService.getUserProperties().setProperty('customSsid', ssid);
        return ssid;
  }


我在代码SpreadsheetApp.getActiveSpreadsheet()getCustomSpreadsheet()的任何地方找到/替换,并且在以后生活过......