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 で、メニュー オプション [ファイル] > [プロジェクト プロパティ] に移動し、 https ://developers.google.com/apps で説明されているように、[プロジェクト キー] プロパティを Script1 の [ライブラリの検索] ダイアログにコピーします。 -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サンプル コードの最後の tine に書いているのですか? 何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 に答える