从 Google Apps 脚本网络应用中获取 JSON 从另一个网络应用中获取 JSON,无需匿名访问
Get JSON from a Google Apps Script web-app from another web-app without anonymous access
首先,这个问题与 Fetch JSON object from Google WebApp from another Google WebApp 重复,但是,这个问题已有 6 年历史,答案不适用于我的情况 -- 详情如下。
--
我有一个 Google Apps Script 网络应用 return JSON 并且发布后它可以作为我和 我组织中的任何人运行 可以访问它。由于种种原因,我不能像answered from the other question.
那样匿名发表
function doGet(request)
{
return ContentService.createTextOutput(JSON.stringify(request)).setMimeType(ContentService.MimeType.JSON);
}
我正在尝试使用 UrlFetchApp.fetch(...)
从另一个网络应用程序调用此网络应用程序,但它似乎 return 一堆 HTML 而不是预期的 JSON输出。
function testIt()
{
var a = UrlFetchApp.fetch("https://script.google.com/a/verizon.com/macros/s/[redacted]/exec");
Logger.log(a.getContentText());
}
我知道第二个网络应用程序,带有 testIt
的那个从 Google 的服务器运行,所以 UrlFetchApp.fetch
调用是匿名的。
必须有一种方法来传递用户的身份验证令牌运行 testIt
?
我试过了,但也没用:
var a = UrlFetchApp.fetch("https://script.google.com/a/verizon.com/macros/s/AKfycbxseotobMLXnid5PT_UpBRWZdNrhhX2EOegeCd4b9gFA2VbAvLm/exec", {
"method":"GET",
"muteHttpExceptions": true,
"headers": {
"Authorization" : "Basic " + ScriptApp.getOAuthToken()
}
});
我是做错了什么还是我想要的是不可能的?
基本上,我有自己的网络应用程序,而其他人也有他们自己的网络应用程序。我正在尝试找到一种方法,他们可以从他们的网络应用程序调用我的网络应用程序来执行他们的网络应用程序无法访问的某些事情(将一些数据写入一些工作表并从我的帐户发送一些电子邮件)。
当使用access token访问Web Apps时,请修改如下。
发件人:
"Authorization" : "Basic " + ScriptApp.getOAuthToken()
到
"Authorization" : "Bearer " + ScriptApp.getOAuthToken()
- 作为本案例的重点,请确认驱动器 API 的范围是否包含在您的范围内。
- 如果不包括,请将
// DriveApp.getFiles()
作为注释行。这样,https://www.googleapis.com/auth/drive.readonly
就包含在范围内了。我认为在 Web Apps 的情况下,这可以用于访问。
参考:
首先,这个问题与 Fetch JSON object from Google WebApp from another Google WebApp 重复,但是,这个问题已有 6 年历史,答案不适用于我的情况 -- 详情如下。
--
我有一个 Google Apps Script 网络应用 return JSON 并且发布后它可以作为我和 我组织中的任何人运行 可以访问它。由于种种原因,我不能像answered from the other question.
那样匿名发表function doGet(request)
{
return ContentService.createTextOutput(JSON.stringify(request)).setMimeType(ContentService.MimeType.JSON);
}
我正在尝试使用 UrlFetchApp.fetch(...)
从另一个网络应用程序调用此网络应用程序,但它似乎 return 一堆 HTML 而不是预期的 JSON输出。
function testIt()
{
var a = UrlFetchApp.fetch("https://script.google.com/a/verizon.com/macros/s/[redacted]/exec");
Logger.log(a.getContentText());
}
我知道第二个网络应用程序,带有 testIt
的那个从 Google 的服务器运行,所以 UrlFetchApp.fetch
调用是匿名的。
必须有一种方法来传递用户的身份验证令牌运行 testIt
?
我试过了,但也没用:
var a = UrlFetchApp.fetch("https://script.google.com/a/verizon.com/macros/s/AKfycbxseotobMLXnid5PT_UpBRWZdNrhhX2EOegeCd4b9gFA2VbAvLm/exec", {
"method":"GET",
"muteHttpExceptions": true,
"headers": {
"Authorization" : "Basic " + ScriptApp.getOAuthToken()
}
});
我是做错了什么还是我想要的是不可能的?
基本上,我有自己的网络应用程序,而其他人也有他们自己的网络应用程序。我正在尝试找到一种方法,他们可以从他们的网络应用程序调用我的网络应用程序来执行他们的网络应用程序无法访问的某些事情(将一些数据写入一些工作表并从我的帐户发送一些电子邮件)。
当使用access token访问Web Apps时,请修改如下。
发件人:
"Authorization" : "Basic " + ScriptApp.getOAuthToken()
到
"Authorization" : "Bearer " + ScriptApp.getOAuthToken()
- 作为本案例的重点,请确认驱动器 API 的范围是否包含在您的范围内。
- 如果不包括,请将
// DriveApp.getFiles()
作为注释行。这样,https://www.googleapis.com/auth/drive.readonly
就包含在范围内了。我认为在 Web Apps 的情况下,这可以用于访问。