Google Apps 脚本:联系人更改时触发脚本?
Google Apps Script: Trigger a script when Contacts change?
我正在尝试让 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());
}
}
}
}
不,联系人 api 没有联系人更改事件。您需要轮询更改。
我正在尝试让 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());
}
}
}
}
不,联系人 api 没有联系人更改事件。您需要轮询更改。