google-apps-script - 使用 Google 电子表格中的 ContactsApp
问题描述
概述:当我在 GoogleAppsScript 函数中调用 ContactsApp.getContact() 时,该函数在从脚本编辑器运行时工作正常。但是,当我尝试使用 Google 电子表格中的函数时,出现权限错误。如何解决此权限错误并通过电子表格中的自定义函数使用 ContactsApp?
详细信息: 我创建一个新的电子表格并打开脚本编辑器并定义以下简单函数:
function example() {
ContactsApp.getContacts();
return 5;
}
第一次从脚本编辑器运行它时,系统会提示我批准对我的联系人的访问。我批准了,该功能运行得很好。我可以添加日志记录并验证它是否按预期工作。
现在回到电子表格中,我在单元格中使用公式“=example()”,期望它将单元格的值设置为 5。相反,单元格显示“#ERROR!” 并将鼠标悬停在单元格上会显示详细错误:
You do not have permission to call ContactsApp.getContacts. Required permissions: https://www.google.com/m8/feeds (line 2)
查看脚本的项目属性,我可以看到它https://www.google.com/m8/feeds
确实被列为必需的 oauth 范围。
如何解决此权限错误并通过电子表格中的自定义函数使用 ContactsApp?
解决方案
我在这里的文档中找到了答案: https ://developers.google.com/apps-script/guides/sheets/functions#advanced
Unlike most other types of Apps Scripts, custom functions never ask users to authorize access to personal data. Consequently, they can only call services that do not have access to personal data, specifically the following:
Cache
HTML
JDBC
Language
Lock
Maps
Properties
Spreadsheet
URL Fetch
Utilities
XML
因此,目前不允许在自定义函数中根据问题需要使用 ContactsApp,因为需要授权,而自定义函数不允许这样做。
推荐阅读
- javascript - 如何将 .js 文件分解为不同的文件,如 PHP 的包含(或要求),这样我就不必使用命名空间
- ionic-framework - 每天开始特定日期的离子本地通知
- javascript - 如何让用户自定义通知条件?
- html - 如何创建 SVG 图标以及如何在 Web 应用程序上实现?
- r - 从r中的数据文件中的列中提取最频繁出现的元素
- node.js - 无法在版本 8 中运行 node js 项目
- python - 如何在python列表中的特定索引处插入元素
- dropdownlistfor - DropDownListFor 不向控制器传输数据
- c# - StreamWriter 写入文件时丢失字符串字符
- node.js - 无法在节点 js 中进行身份验证