【问题标题】:Google API Executable permission denied errorGoogle API 可执行权限被拒绝错误
【发布时间】:2017-05-21 16:37:54
【问题描述】:

我有一个小型 Google Apps 脚本,已部署为 API 可执行文件。 虽然我已经使用我正在使用的范围(电子表格)的有效令牌进行了调用,但我无法通过这个 403 PERMISSION_DENIED 错误。 我现在正在API's Explorer 上测试这个,但出现了同样的错误。

有人知道我可能会错过什么吗?

我的脚本很简单(仍然不完整,但它可以运行 - 对于这些初始测试应该足够了):

OAuth Scope required by script (copied from API's Explorer):
https://www.googleapis.com/auth/spreadsheets

function myFunction(get) {
  var ss = SpreadsheetApp.openById("1axDlnPaoEwhlb_Vs5SLBvkGJrR-fSeOLuHEdSBXCTBg"); // I'm not getting anything from the sheet at this point, I included it just to make sure that the script requires the spreadsheets scope

  get += " " + "success!";

  return  ContentService.createTextOutput(get);
}

请求(从 API 的资源管理器中复制):

POST https://script.googleapis.com/v1/scripts/1d1EKj7vi-gzC0gB02qjw_qBPE1zSrZtJp-YUWuKm3NL3-3t6Sixpm0TZ:run?key={YOUR_API_KEY}

{
 "function": "myFunction",
 "parameters": [
 "Hello world!"
 ]
}

响应(从 API 的资源管理器中复制):

{
    "error": {
        "code": 403,
        "message": "The caller does not have permission",
        "status": "PERMISSION_DENIED"
    }
}

【问题讨论】:

    标签: google-apps-script google-cloud-platform


    【解决方案1】:

    您可能需要检查以下 3 件事:

    • 确保您的应用脚本与正确的开发控制台项目相关联。
    • 启用 Apps 脚本执行 API。
    • 如果您使用 Method: scripts.run 在 Apps 脚本中运行函数,如果您是该脚本的所有者,请设置 devMode: true。否则,使用默认值 false

    此外,您应该满足Using the Execution API 中列出的要求。

    请参阅此相关SO post 以获取更多见解。

    【讨论】:

    • 问题是第一点:我的脚本与错误的控制台项目相关联。
    【解决方案2】:

    该脚本应与与使用的 OAuth 2.0 客户端 ID 对应的开发者控制台项目 ID 相关联(在您当前脚本的脚本编辑器中:Resources > Cloud Platform Project,然后输入您的项目 ID 号) 这就是 我的 脚本无法正常工作的原因(您的可能会有所不同,请参阅Teyam's 答案,我已将其标记为正确的答案)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-31
      • 2022-08-03
      • 2016-04-15
      • 1970-01-01
      • 2016-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多