guestlist [j] .getName()不返回名称

时间:2017-07-06 15:32:02

标签: google-apps-script google-calendar-api

我正在尝试修改daubejb在线找到的脚本,以便通过Google日历活动创建Google文档。

Google网站上的参考资料显示,如果名称不可用,getName()命令应显示访客的名称或电子邮件。但是,我尝试时没有显示任何内容。当我使用getEmail()命令时,我收到电子邮件就好了,但我更愿意得到这个名字。

function createMeetingNotesNextTimePeriod() {

 //------VARIABLES--
 // define a custom style for all data labels
 var labelStyle ={};
 labelStyle[DocumentApp.Attribute.BOLD] = true;
 labelStyle[DocumentApp.Attribute.FONT_SIZE] = 11;

 // get today's date
 var today = new Date();

 // create a formatted version of today's date
 var formatted_today = Utilities.formatDate(today, "EDT","yyyy-MM-dd");   

 // number of hours from now to check for meetings
 var hours = 2

 // create variable for now
 var now = new Date();

 // create variable for number of hours from now in milliseconds
 var period_from_now = new Date(now.getTime() + (hours * 60 * 60 * 1000));

 //------GET EVENTS/ATTRIBUTES FOR TIME PERIOD FROM NOW--------------
 // retrieve all calendar events for time period
 var events = CalendarApp.getDefaultCalendar().getEvents(now, period_from_now, {search: '@notes'}) ;

 // loop through each event an get meeting attributes, 
 for (var i=0;i<events.length;i++) {
   var title = events[i].getTitle();
   var description = events[i].getDescription();
   var eventstart = events[i].getStartTime();
   var eventend = events[i].getEndTime();
   var location = events[i].getLocation();
   var owner = events[i].getCreators();
   var guestlist = events[i].getGuestList();

   //----------CREATE MEETING NOTE DOC -------------  
   // create a google doc with the meeting name as the title
   var file_exists = DriveApp.getFilesByName(title).hasNext();

   // check to see if file already exists, if does skip if loop
   if ((file_exists == false) && (guestlist.length >= 1)) {
    var doc = DocumentApp.create(title);

    // loop through event guests and get their emails and status
    for (var j=0;j<guestlist.length;j++) {
      var name = guestlist[j].getName();
      var guestStatus = guestlist[j].getGuestStatus();
      doc.getBody().appendParagraph(name + ': ' + guestStatus);
    }

    doc.getBody().editAsText()
    .insertText(0, 'Invités:\n')
    .setAttributes(0, 9, labelStyle);

    doc.getBody().editAsText()
    .insertText(0, 'Description:' + '\n\n' + description + '\n\n')
    .setAttributes(0, 11, labelStyle);

    doc.getBody().editAsText()
    .insertText(0, 'Organisateur:  ' + owner + '\n\n' )
    .setAttributes(0, 11, labelStyle);

    doc.getBody().editAsText()
    .insertText(0, 'Location:  ' + location + '\n\n')
    .setAttributes(0, 8, labelStyle);

    doc.getBody().editAsText()
    .insertText(0, 'Fin:  ' + eventend + '\n\n')
    .setAttributes(0, 3, labelStyle);

    doc.getBody().editAsText()
    .insertText(0, 'Début:  ' + eventstart + '\n')
    .setAttributes(0, 5, labelStyle);

    doc.getBody().editAsText()
    .insertText(0, title + '\n\n')
    .setFontSize(0, title.length, 14)
    .setBold(0, title.length, true)
    .setForegroundColor(0, title.length, '#cc0000');

   }  // if for file exists

  }  // for loop for each event 

}  // functionCreateMeetingNotesNextTimePeriod

提前致谢。

1 个答案:

答案 0 :(得分:0)

如果getEmail()有效,则仅表示未提供名称,因此getName()不会返回任何结果。 API工作正常。

我建议您使用其他日历和有效的访客姓名来查看是否仍然没有结果。