问题
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