【问题标题】:Polling a Google Contacts change using an apps script使用应用脚本轮询 Google 通讯录更改
【发布时间】:2021-05-19 14:40:16
【问题描述】:

我需要检测我的通讯录中的变化,不幸的是 People API 没有提供这样的功能。我在一些博客中读过需要投票。我没有找到任何 API 来投票 https://developers.google.com/contacts/v3/reference 谁能建议我如何实现此功能?

【问题讨论】:

  • 目前此功能在当前版本的联系人 API 中尚不可用。您可能需要使用此链接中的说明请求此特定功能:Submit ideas for Google Workspace
  • 你在寻找什么样的改变?

标签: google-apps-script google-contacts-api


【解决方案1】:

如果您的联系人数量或您的联系人电子邮件数量发生变化,您可以使用此类功能接收和发送电子邮件。

function sendEmailIfContactChange() {
  const gObj = PropertiesService.getScriptProperties().getProperties();
  const contacts=ContactsApp.getContacts();
  var n=0;
  contacts.forEach((c)=>{c.getEmails().forEach((e)=>{n++;});});
  if(!gObj.hasOwnProperty('contacts')) {
    gObj.contacts=contacts.length;
    gObj.emails=n;
    PropertiesService.getScriptProperties().setProperties(gObj);
    return;
  } else {
    let pc = gObj.contacts;
    let pe = gObj.emails;
    gObj.contacts = contacts.length;
    gObj.emails = n;
    PropertiesService.getScriptProperties().setProperties(gObj);
    if(pc != contacts.length || pe != n) {
      GmailApp.sendEmail(gobj.globals.privateemail,'Contacts Have Change',`Old Contact: ${pc} New Contacts: ${contacts.length} \nOld Emails: ${pe} New Emails: ${n}`);
    }
  } 
}

您可以像这样创建轮询触发器:

function createPollingTrigger() {
  const ts = ScriptApp.getProjectTriggers().map(t=>t.getHandlerFunction());
  if(!~ts.indexOf('sendEmaiIfContactChange')) {
    ScriptApp.newTrigger('sendEmailIfContactChange').timeBased().everyHours(2).create();
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-25
    • 1970-01-01
    • 2016-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多