【发布时间】:2016-04-19 21:20:27
【问题描述】:
我正在尝试使 Google 群组与我的 Google 通讯录保持同步。
我编写了一个 Google Apps 脚本,将电子邮件从我的联系人复制到 Google 群组,但我需要一种方法来触发它。
编辑联系人时是否有事件?
这是我的同步代码:
function copyContactsToGroups() {
var contacts = ContactsApp.getContacts();
Logger.log("found " + contacts.length + " contacts");
var groupEmail = '[my group email]';
for(var i = 0; i < contacts.length; i++) {
var contact = contacts[i];
// Name
if (contact.getFullName() == null || contact.getFullName().length == 0)
{
continue;
}
// Email
emails = contact.getEmails();
for( var j = 0; j < emails.length; j++) {
var existing_member;
try {
existing_member = AdminDirectory.Members.get(groupEmail, emails[j].getAddress());
}
catch (e) {
existing_member = null;
}
if (existing_member == null) {
var key = {
email: emails[j].getAddress(),
role: 'MEMBER'
};
AdminDirectory.Members.insert(key, groupEmail);
Logger.log("Added: " + emails[j].getAddress() + " for " + contact.getFullName());
}
else {
Logger.log("Already present: " + emails[j].getAddress());
}
}
}
}
【问题讨论】:
标签: google-apps-script triggers google-contacts-api