0
//script calling the published script, this script is in the account 1
function callScript(){
    try{//published url
       var response =UrlFetchApp.fetch("https://script.google.com/macros/s/../exec?  calendar='CalendarName'");//calendar name as parameter

    }catch(e){
  Logger.log(e);
 }
 Logger.log(response.getContentText());
}

//account 2
//the code is published, it will run as the user who call the script(account 1), the   access is for anyone 
function doGet(e){//published script

  var app = UiApp.createApplication();
  var calendar=e.parameter.calendar; //calendar name as parameter
  // Determines how many events are happening now 
  var now = new Date();
  var oneMinuteFromNow = new Date(now.getTime() + (60 * 1000));
  var events = CalendarApp.getCalendarsByName(calendar)  [0].getEvents(now,oneMinuteFromNow);
  var email=Session.getActiveUser().getEmail();
  for(i in events){
     var tituloEvento=events[i].getTitle();
     var descEvento= events[i].getDescription();
     var insertar=leerBD(email,tituloEvento,descEvento);
     if (insertar) {
       var inserto=insertarBD(email,tituloEvento,descEvento); 
     } 
  }  
  return ContentService.createTextOutput(e.parameter.string.calendar);
 }

我想在帐户 2 中调用脚本并将日历名称作为参数传递,在帐户 2 中,脚本将以调用脚本并获取一些事件的用户身份运行

4

2 回答 2

0

假设 Script1 是“客户端”,或者调用“服务器”的脚本,Script2。

在已发布的 Script2 中,转到菜单选项“文件 > 项目属性”,并将“项目密钥”属性复制到 Script1 的“查找库”对话框中,如下所述: https ://developers.google.com/apps -script/guide_libraries#writingLibrary

您还需要公开要从 Script1 处理的 Script2 函数,并照常传入您的参数:

script1Var = Script2.myFunction(script1Param)
于 2014-02-21T04:55:34.250 回答
0

您不需要在 URL 中包含的参数中使用引号,请尝试如下:

   var response =UrlFetchApp.fetch("https://script.google.com/macros/s/../exec?calendar=CalendarName");//calendar name as parameter

并且 :

你为什么要写e.parameter.string.calendar在你的示例代码的最后一部分?是string为了什么?我想目的是返回日历名称以外的其他内容......请解释一下。

这是一个工作演示,我删除了您的特定函数调用并使用公共议程。它只返回记录器中日历的名称。

//script calling the published script, this script is in the account 1
function callScript(){
    try{//published url
       var response =UrlFetchApp.fetch("https://script.google.com/macros/s/AKfycbxg-XiPOSIzTATNO520r2DYqLWFjSJXIZ4h-9G_4eV4UZTgxnjo/exec?calendar=test_agenda");//calendar name as parameter

    }catch(e){
  Logger.log(e);
 }
 Logger.log(response.getContentText());
}

//account 2
//the code is published, it will run as the user who call the script(account 1), the   access is for anyone 
function doGet(e){//published script

  var app = UiApp.createApplication();
  var calendar=e.parameter.calendar; //calendar name as parameter
  // Determines how many events are happening now 
  var now = new Date();
  var oneMinuteFromNow = new Date(now.getTime() + (60 * 1000));
  var events = CalendarApp.getCalendarsByName(calendar)  [0].getEvents(now,oneMinuteFromNow);
  var email=Session.getActiveUser().getEmail();
  for(i in events){
     var tituloEvento=events[i].getTitle();
     var descEvento= events[i].getDescription();
  }  
  return ContentService.createTextOutput(e.parameter.calendar);
 }
于 2014-02-21T06:29:22.420 回答