导入Google联系人-如何排除州/国家(德国,美国等)

问题描述 投票:0回答:2

如何将联系人详细信息从(导入到工作表)导入中排除?我想导入包括地址字段在内的联系人,但不包含州(美国,德国等)。

im使用.getAddresses()

结果为:马克斯·穆斯特曼第一街1号88662乌伯林根DE

我想要不带“ DE”的地址:

马克斯·穆斯特曼

第一街1

88662乌伯林根

来自德国的问候,感谢您对Advance的帮助!Nico

不是我的代码-我仅根据我的需要对其进行了编辑:

function getContacts(groupName) {
  Utilities.sleep(200);
  
  if(groupName !== "") {
    var group  = ContactsApp.getContactGroup(groupName);
  } else {
    groupName = 'System Group: My Contacts';
  }
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();
  var contacts = ContactsApp.getContactsByGroup(group);
  
  var allContacts = []; 
  var contactDetails = [];
  var data, numData, dataArray = [], extraArray = [];
  var contact_length = contacts.length;
  //var index = 0;
  var i = 0,batch_limit = 500;
  if(contact_length == 0)
  {
    if(groupName == '')
    {
       Browser.msgBox("Keine Kontakte in deinem Account gefunden");  
    }
    else
    {
       Browser.msgBox("Keine Kontakte in "+groupName);
    }    
    return;
  }
  else if(contact_length > 7000)
  {
    Browser.msgBox("Too many contacts.Can process upto 7000 contacts only");
    return;
  }
  for(i; i < contact_length; i++) {
    allContacts[i] = [];
    //contactDetails[0] = index++;

    contactDetails[1] = contacts[i].getPrefix();
    contactDetails[2] = contacts[i].getGivenName();
    contactDetails[3] = contacts[i].getFamilyName();
    contactDetails[0] = contacts[i].getNickname();
    
    
    //contactDetails[3] = contacts[i].getSuffix();
    
    //data = contacts[i].getEmails(); ----- original
    // data = contacts[i].getEmails(ContactsApp.Field.WORK_EMAIL); // ----- modified
    data = contacts[i].getEmails(); // ----- modified
    numData = data.length;
    for(var j = 0; j < numData; j++) {
      dataArray[j] = data[j].getAddress();
    }
    //contactDetails[3] = dataArray.toString(); ----- original
    contactDetails[6] = dataArray.join("\n");  // ----- modified
    dataArray = [];
    
    data = contacts[i].getPhones(ContactsApp.Field.MOBILE_PHONE); // ----- modified
    numData = data.length;
    for(var j = 0; j < numData; j++) {
      dataArray[j] = data[j].getPhoneNumber();
    }
    //contactDetails[4] = dataArray.toString(); ------ original
    contactDetails[7] = dataArray.join("\n");  // ----- modified
    dataArray = [];

    //data = contacts[i].getContactGroups(); // <-- This call takes anywhere between 0.03 seconds to 1.45 seconds. 
    data = contacts[i].getContactGroups();
    numData = data.length;
    for(var j = 0; j < numData; j++) {
      if(data[j].getName() == 'System Group: My Contacts')
      {
        continue;
      }
      else
      {
        dataArray[j] = data[j].getName();
        Logger.log(dataArray[i]);
      }
    }
    //contactDetails[9] = dataArray.toString(); ------ original
    contactDetails[11] = dataArray.join("\n");  // ----- modified
    dataArray = [];
    
    //data = contacts[i].getPhones(); ----- original
    data = contacts[i].getPhones(ContactsApp.Field.WORK_PHONE); // ----- modified
    numData = data.length;
    for(var j = 0; j < numData; j++) {
      dataArray[j] = data[j].getPhoneNumber();
    }
    //contactDetails[4] = dataArray.toString(); ------ original
    contactDetails[8] = dataArray.join("\n");  // ----- modified
    dataArray = [];
    
    // new section for home_phone ----- start
    data = contacts[i].getPhones(ContactsApp.Field.HOME_PHONE);
    numData = data.length;
    for(var j = 0; j < numData; j++){
      dataArray[j] = data[j].getPhoneNumber();
    }
    contactDetails[9] = dataArray.join("\n");
    dataArray = [];
    // new section for home_phone ----- end
    
    data = contacts[i].getCompanies();
    numData = data.length;
    for(var j = 0; j < numData; j++) {
      dataArray[j] = data[j].getCompanyName();
      extraArray[j] = data[j].getJobTitle();
    }
    //contactDetails[5] = dataArray.toString(); ----- original
    contactDetails[4] = dataArray.join("\n");  // ----- modified
    dataArray = [];
    //contactDetails[6] = extraArray.toString(); ------ original
    contactDetails[5] = extraArray.join("\n");  // ----- modified
    
    data = contacts[i].getAddresses();
    numData = data.length;
    for(var j = 0; j < numData; j++) {
      dataArray[j] = data[j].getAddress();
    }
    //contactDetails[7] = dataArray.join("\n"); ------ original
    contactDetails[10] = dataArray.join("\n");  // ----- modified
    dataArray = [];
    
    contactDetails[12] = contacts[i].getNotes();
    
    data = contacts[i].getCustomFields();
    numData = data.length;
    for(var j = 0; j < numData; j++) {
      dataArray[j] = data[j].getValue();
    }
    //contactDetails[7] = dataArray.join("\n"); ------ original
    contactDetails[20] = dataArray.join("\n");  // ----- modified
    dataArray = [];  
    data = [];
    
    contactDetails[14] = 'saved';
    contactDetails[15] = contacts[i].getId();

    for(var j = 0; j < 16; j++) {
      allContacts[i][j] =  contactDetails[j];
    }    
    Logger.log(i);
    printContacts(allContacts, i);
  }  
google-apps-script google-contacts-api
2个回答
0
投票

您可能最终必须使用字符串操作。由于地址是作为字符串输入到“联系人”的,因此不会按(街道编号,街道名称,单位编号,国家/地区,城市等)进行细分。

因此,当您获取它们时,API返回一个包含所有地址信息(包括国家/地区)的字符串。

© www.soinside.com 2019 - 2024. All rights reserved.