1

抱歉我的英语很差...我尝试使用 Google Apps Script - Contacts Service 阅读我的联系人中的信息。

姓名、电子邮件、地址、电话没有问题,但我无法读取日期(我想获取联系人的出生日期)。如何阅读“日期字段”?

    for (var i=0; i<contacts.length; i++) {
    Name = contacts[i].getFullName();

    EmailArray = contacts[i].getEmails(ContactsApp.Field.HOME_EMAIL);
    if (EmailArray.length)
      Email = contacts[i].getEmails(ContactsApp.Field.HOME_EMAIL)[0].getAddress();
    if (!Email){
      EmailArray = contacts[i].getEmails(ContactsApp.Field.WORK_EMAIL);
      if (EmailArray.length)
        Email = contacts[i].getEmails(ContactsApp.Field.WORK_EMAIL)[0].getAddress();
    }

    AddressArray = contacts[i].getAddresses(ContactsApp.Field.HOME_ADDRESS);
    for ( var j = 0; j < AddressArray.length; j++ ) {
      Address = AddressArray[j].getAddress();
      AddressSplit = Address.split(/\r\n|\r|\n/);
      Rue = AddressSplit[0];
      Code = AddressSplit[1].split(" ")[0];
      Ville = AddressSplit[1].split(" ")[1];
    }

    var HomePhone = contacts[i].getHomePhone();
    var MobilePhone = contacts[i].getMobilePhone();

    //HERE IS THE PROBLEM
    DatesArray = contacts[i].getDates();
    // Never pass here... How to read the DateField ?
    for ( var j = 0; j < DatesArray.lenght; j++ ) {
      var date = contacts[i].getDates()[j];
      var day = date.getDay();
      var month = date.getMonth();
      var year = date.getYear();
    }
  }
4

2 回答 2

1

我找到了解决方案……过了一会儿!没有记录联系人服务...

var dateArray = new Array(), day, month = new String, year;
var monthArray = ["0", "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"];

dateArray = contacts[i].getDates(ContactsApp.Field.BIRTHDAY);
for(var j in dateArray){
  day = dateArray[j].getDay();
  month = monthArray.indexOf(dateArray[j].getMonth().toString());
  year = dateArray[j].getYear();
  sheet.getRange(1*i+2, 3, 1, 1).setValue(day + "/" + month + "/" + year);
}
于 2012-12-12T20:35:06.603 回答
0

这应该这样做

DatesArray.length
于 2012-12-11T01:18:47.580 回答