Haq*_*waz 16 google-sheets google-apps-script
我正在从谷歌电子表格中的脚本编辑器发送 http 请求,但我不断收到以下错误消息:
`Google Apps Script: You do not have permission to call UrlFetchApp.fetch. Required permissions: https://www.googleapis.com/auth/script.external_request`
Run Code Online (Sandbox Code Playgroud)
我正在使用 onEdit 功能:
function onEdit(e){
var ui = SpreadsheetApp.getUi();
var response = UrlFetchApp.fetch('http://www.eur-api.idomoo.com/');
Logger.log(response.getContentText());
}
Run Code Online (Sandbox Code Playgroud)
我不知道为什么我会收到这个错误?我还授予了 script.external_request 范围的权限,任何帮助将不胜感激。
Yuc*_*uci 18
当用户更改电子表格中的值时,简单触发器会调用 onEdit。
但是,简单的触发器无法访问需要授权的服务,例如UrlFetchApp.fetch
. 请参阅 Google Apps 脚本指南
您可以做的是简单地将函数 onEdit 重命名为其他名称,例如 atEdit,从而移除简单触发器。然后按照Current project's triggers
菜单...
并添加一个触发器以在 发生时调用On edit
。
在创建触发器时,您将按照向导授予您的应用程序脚本权限以连接到外部服务。
con*_*rpw 10
有两种方法可以解决这个问题
I. 更新您的清单并将该行添加"https://www.googleapis.com/auth/script.external_request"
到oauthScopes
{
"timeZone": "Europe/Moscow",
"oauthScopes": [
...
"https://www.googleapis.com/auth/script.external_request"
],
"dependencies": {
...
},
"exceptionLogging": "STACKDRIVER"
}
Run Code Online (Sandbox Code Playgroud)
二. 或者从您的清单中完全删除oauthScopes
密钥
您可以在此处找到如何编辑清单Manifests
您需要授权您的脚本访问该external_request
服务。如果您是项目的所有者,您应该能够通过运行并确认该oauth
页面来授予访问权限。
在此处阅读有关身份验证的更多信息:https ://developers.google.com/apps-script/guides/services/authorization
归档时间: |
|
查看次数: |
5544 次 |
最近记录: |