【发布时间】:2014-10-28 08:32:50
【问题描述】:
我正在使用 gogole html web app scridpt,从那里我必须输入 index.html 并将该信息作为表单对象传递给 code.gs 文件,它使用开始时间和结束时间以及一些用户 ID abc.com 组织中的候选人。
现在我必须在日历中找到所有使用的电子邮件 ID 的空闲时间。
var user1_Cal = CalendarApp.getCalendarById('user1@abc.com');
var user2_Cal = CalendarApp.getCalendarById('user2@abc.com');
查找 date1 和 date2 期间的所有空闲和忙碌
script.html
<div>
<form id="myform">
<input type="user1" name="user1" id="user1" placeholder="Enter your id">
<br>
<input type="user2" name="user2" id="user2" placeholder="Enter your id">
<br>
<input type="start" name="start" id="start" placeholder="start">
<br>
<input type="end" name="end" id="end" placeholder="end">
<br>
<input type="submit" value="myform_val">
</form>
</div>
<?!= HtmlService.createHtmlOutputFromFile('css').getContent(); ?>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>
$( document ).ready(function() {
$( "#myform" ).submit(function() {
google.script.run.withSuccessHandler(function(ret){
console.log(ret);
}).addEmail(this); //"this" is the form element
});
});
</script>
code.gs
function doGet() {
try{
var html = HtmlService.createTemplateFromFile('index').evaluate().setTitle('Web App').setSandboxMode(HtmlService.SandboxMode.NATIVE);
}catch(error){
var errorSheet = SpreadsheetApp.openById('errorsheet_id_here').getSheetByName('errors');
var cell = errorSheet.getRange('A1').offset(errorSheet.getLastRow(),0);
cell.setValue(new Date() + " function doGet: " + error);
}
return html;
}
function addEmail(form){
try{
// here we can use the form.user1, form.user2, form.start, form.end
var user1_Cal = CalendarApp.getCalendarById(form.user1);
var user2_Cal = CalendarApp.getCalendarById(form.user2);
/// using these two candidate info and between start and end time we have to find all the free time and the put into the output_array and that can be returned back to index.html
Logger.log(user1_cal.getName());
var today = new Date();
Logger.log(user1_cal.getEventsForDay(today));
var events = user1_cal.getEventsForDay(today);
Logger.log('Number of events: ' + events.length);
// I am getting the number of events but want the actual start and end time.
var myval = JSON.stringify(output_array);
return myval;
}
catch(error)
{
var errorSheet = SpreadsheetApp.openById('sheet_id').getSheetByName('errors');
var cell = errorSheet.getRange('A1').offset(errorSheet.getLastRow(),0);
cell.setValue(new Date() + " and error is : " + error);
}
}
问题:如何获取用户日历空闲忙碌详情 注意:在谷歌日历业务应用程序中,设置为
【问题讨论】:
-
我认为您需要查询 freebusy 以获取该信息 developers.google.com/google-apps/calendar/v3/reference/…
-
那个api使用了第三方代码,需要通过,我想直接在GAS里面把值放到output_array中
标签: javascript google-apps-script google-calendar-api google-apps