Writing into My Contacts

大憨熊 提交于 2020-12-13 05:02:58

问题


I have been trying to create contact in My Contacts folder, so it could be synced with my phone. I would't mind using groups, but their synchronization is broken on iPhone. Anyway, I am using this script:

function update() {
  var group = ContactsApp.findContactGroup('My Contacts');
  group.addContact(ContactsApp.createContact('Fido','McDog', 'fido@example.com'));
  var contact = ContactsApp.findByEmailAddress('fido@example.com');
  contact.setWorkPhone('123123123123');
}

If I use any other name for 'My Contacts', the script works perfectly. Otherwise I get error: TypeError: Cannot call method "addContact" of null. (line 3)

Is that some sort of limitation from Google?

Thanks.


回答1:


It appears that the Group My Contacts is actually called "System Group: My Contacts". Other system groups are similarly named so, to add to My Contacts rather than Other ...

function test() {
 var group = ContactsApp.getContactGroup("System Group: My Contacts");
 group.addContact(ContactsApp.createContact('Fido','McDog', 'fido@example.com'));
 var contact = ContactsApp.findByEmailAddress('fido@example.com');
 contact.setWorkPhone('123123123123');
 }


来源:https://stackoverflow.com/questions/14708641/writing-into-my-contacts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!