【问题标题】:Google Apps Script: Trigger a script when Contacts change?Google Apps 脚本:联系人更改时触发脚本?
【发布时间】: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


    【解决方案1】:

    不,没有联系人 API 的联系人更改事件。您需要轮询更改。

    【讨论】:

    • :-( 好的,我将使用基于时间的触发器。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-02
    • 2016-12-08
    • 1970-01-01
    • 1970-01-01
    • 2023-02-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多