【问题标题】:How to set permissions to allow Google Sheets to use an Apps Script to query my Contacts?如何设置权限以允许 Google 表格使用 Apps 脚本查询我的联系人?
【发布时间】:2018-04-04 08:59:41
【问题描述】:

我有一个 Google 表格,我想检查一个电子邮件地址是否已存在于我的联系人列表中。

我用这个函数写了一个 Apps 脚本

function isAContact(email) {
    if (null != ContactsApp.getContact(email)) {
        return 1;
    }

    return 0;
}

如果我直接在 Google Apps 脚本中运行此函数,它会在第一次运行时请求许可后正常运行。

当我在 Google 表格中调用此函数时

=isAContact(H4) // H4 is a cell with an email address

它抱怨 调用 getContact() 的权限被拒绝

如何允许此电子表格使用 Contacts Api?

【问题讨论】:

    标签: google-apps-script google-sheets google-contacts-api custom-function


    【解决方案1】:

    自定义函数不能做任何需要权限的事情: https://developers.google.com/apps-script/guides/sheets/functions

    解决方法包括: 定时触发器每 5 分钟将您的联系人列表拉入隐藏表并设置您的比较。

    从自定义菜单触发时,将您的函数更改为在活动范围或预设范围上工作: https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app#getUi()

    【讨论】:

    • 嗯,我错过了文档的那部分 :( 感谢您的提示。我会接受您的建议。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-02
    相关资源
    最近更新 更多