//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中,腳本將以調用腳本和獲取某些事件的用戶身份運行如何從另一個Google腳本調用已發佈的Google腳本?腳本在不同的帳戶
我假設你已經爲「服務器」應用程序正確設置了訪問權限。 –
Serge,我忘了刪除最後一個字符串中的字符串,而且,我必須在帳戶1中共享日曆嗎?我測試了它並且響應文本相同,它看起來像一個驅動器網頁「<! DOCTYPE html>
... 」而不是帳戶2的日曆名稱,謝謝,問候 – user3325434