【发布时间】:2020-02-26 11:00:42
【问题描述】:
我正在尝试在 google apps 脚本中使用来自 google docs API 的以下代码进行测试:
var f = UrlFetchApp.fetch("https://docs.googleapis.com/v1/documents/1ys6KIY1XOhPHrgQBJ4XxR1WDl0etZdmR9R48h2sP2cc:batchUpdate", {
method:"post",
body: JSON.stringify({
"requests": [
{
"deleteContentRange": {
"range": {
"startIndex": 1,
"endIndex": 80
}
}
}
]
}),
headers: {
Authorization:"Bearer " + ScriptApp.getOAuthToken(),
"Content-Type": "application/json"
}
})
Logger.log(f)
(另外,当我在浏览器中手动输入 oauth 令牌时,结果与下面相同);但是,我收到一个错误:
{
"error": {
"code": 403,
"message": "Google Docs API has not been used in project 861341326257 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/docs.googleapis.com/overview?project=861341326257 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
"status": "PERMISSION_DENIED",
"details": [
{
"@type": "type.googleapis.com/google.rpc.Help",
"links": [
{
"description": "Google developers console API activation",
"url": "https://console.developers.google.com/apis/api/docs.googleapis.com/overview?project=861341326257"
}
]
}
]
}
}
即使我可以在 google 应用程序脚本中使用 DocumentApp,这似乎是同一件事(或者是同一件事)?
无论如何,当我转到该链接时,它是一个错误(预期),因为没有真正的“项目”要激活,因为谷歌应用程序脚本在幕后做了很多事情来使 api 工作。
那么如何绕过谷歌应用脚本中的这个错误呢?顺便说一句,我的清单文件如下所示:
{
"timeZone": "America/New_York",
"dependencies": {
},
"oauthScopes": [
"https://www.googleapis.com/auth/documents",
"https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/script.external_request"
],
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8"
}
所以我认为范围是包括在内的。
有什么想法吗?
【问题讨论】:
标签: javascript http google-apps-script fetch google-docs