【发布时间】:2021-05-24 11:49:46
【问题描述】:
我有一个 Google 应用程序脚本项目,我将其用作 网络应用程序,以将从网页(仅限 JavaScript)收集的一些数据保存到 我的 Google 表格(想想它只是我一个简单的数据库)。
除了我的帐户之外,没有必要对其他任何人使用身份验证,因为我根本不会将他们的帐户/数据用于任何事情。我只需要使用我的帐户,因此,当我部署它时,我会使其以我的身份执行,并且任何人都可以访问:
.
当我在上一个屏幕之后单击部署时,它会要求我允许(同意对话框)访问我的帐户数据,我授予了它,之后一切正常,对该脚本的 HTTP 请求工作正常。
.
问题是:
此授权在 3-5 天后到期(我不确定)并且脚本停止工作,我发现当对其的 HTTP 请求返回 error 403
要解决此问题并使其再次运行,我需要从 Google 应用脚本编辑器 再次运行该脚本,该编辑器再次请求权限(同意):
.
我不能这样使用它,当授权被撤销时网页停止工作!
我没有发布脚本(我不想/不需要)。是吗?
我的问题是,我怎样才能以一种使其持续存在的方式添加授权,并且不再一遍又一遍地询问我?
Google 应用脚本上的脚本是这样工作的:
function doPost(request) {
return checkRequest(request);
}
function checkRequest(request) {
//check the request & save the sent data to a google sheet here;
//...
return sendResponse({
success: true,
data: {result: 'Saved the data!' }
});
}
function sendResponse(response) {
return ContentService
.createTextOutput(JSON.stringify(response))
.setMimeType(ContentService.MimeType.JSON);
}
我使用 Ajax HTTP POST 请求从网页调用它,如下所示:
jQuery.ajax({
url: 'https://script.google.com/macros/s/{script-id}/exec',
method: 'POST',
dataType: "json",
data: {key: 'value'},
success: function (response) {
console.log(response);
},
error: function (response) {
console.error(response);
}
});
这是授权过期几天后脚本返回的响应:
【问题讨论】:
-
您的第三方应用和服务设置是什么? support.google.com/accounts/answer/3466521?hl=en
-
@RafaGuillermo ,我没有! i.imgur.com/OGXkrhy.png
-
查看this page 了解可能的原因列表 - 如果其中任何一个看起来可行,请告诉我
标签: google-apps-script google-cloud-platform authorization google-developers-console