【问题标题】:Unable to add an address to a Contact via Google Apps Script [SOLVED]无法通过 Google Apps 脚本向联系人添加地址 [已解决]
【发布时间】:2020-10-25 07:28:37
【问题描述】:

我可以通过 Google Apps 脚本创建联系人,并添加电话号码,但我无法添加地址,收到错误消息“找不到您请求的资源。”

注意:fName、actualLastName、email、address & phone1 都是字符串

//  create the Contact
var newContact = ContactsApp.createContact(fName, actualLastName, email);
var newName = newContact.getFullName();
Logger.log("newName: " + newName);
Logger.log("New contact added");



//  attempt to add the address - DOESN'T WORK
try {
  Logger.log("Wanting to add this address: ", address);
  newContact.addAddress(ContactsApp.Field.WORK_ADDRESS, address);  
  Logger.log("Address added");
} catch(err) {
  Logger.log("Stumbled while trying to add address: " + err.message);
  Browser.msgBox("Stumbled while trying to add address to contact");
}

记录的错误消息是:“尝试添加地址时出现信息错误:找不到您请求的资源。”

添加电话号码可以正常工作:

newContact.addPhone(ContactsApp.Field.MOBILE_PHONE, phone1);

联系人被添加到相应的组中:

var group = ContactsApp.getContactGroup("System Group: My Contacts");
group.addContact(newContact);

【问题讨论】:

  • 虽然我不确定这是否是您问题的直接解决方法,例如,该线程中的评论方法对您的情况有用吗? stackoverflow.com/q/64200243/7108653
  • 感谢您的回复。我很高兴你的问题得到了解决。我认为这可能对其他用户也有用。我将其发布为答案。你能确认一下吗?不幸的是,我没有在问题跟踪器上检查过这种情况。如果您在问题跟踪器中找不到此问题,我建议您报告它。
  • 确实如此。我已在您的回答中添加了评论。
  • 嗨,我无法重现这种行为。使用您的原始代码时,我没有收到任何错误。你还在经历这种情况吗?
  • @lamblichus 奇怪的是,它现在似乎对我有用 ID 调用。我会进一步检查。

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


【解决方案1】:

作为一种解决方法,我想提出以下修改。在此修改中,在创建联系人时检索联系人 ID。并且,addPhoneaddAddress 用于使用联系人 ID 检索联系人对象。

修改脚本:

var newContact = ContactsApp.createContact(fName, actualLastName, email);
var contactId = newContact.getId();
var c = ContactsApp.getContactById(contactId);
c.addAddress(ContactsApp.Field.WORK_ADDRESS, address);

参考:

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-04
  • 2012-10-02
相关资源
最近更新 更多