13

我在脚本编辑器中创建了一个脚本,将其发布为“部署为 API 可执行文件”。在这个脚本中,我为我的工作表提供了一个 doc_id,并定义了一个函数来从该工作表中获取数据。

然后我去https://developers.google.com/apps-script/execution/rest/v1/scripts/run测试执行 API。我添加了范围,授权了应用程序并尝试了它。我收到以下错误消息:

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

有人可以告诉我我做错了什么吗?

4

6 回答 6

26

确保应用脚本与正确的开发控制台项目相关联。

该脚本应与与使用的 OAuth 2.0 客户端 ID 对应的开发控制台项目 ID 相关联(此开发控制台项目还应启用“Apps Script Execution API”)。

要更改应用脚本的开发者控制台项目,请选择以下菜单项:资源 > 开发者控制台项目...

在此屏幕上输入开发控制台的项目编号。

于 2015-10-08T06:32:15.440 回答
11

即使一切正常,您也可以通过"devMode":true. 多亏了这一点,我在尝试为其他用户部署时浪费了半天时间。

仅供日后参考。

于 2016-05-12T14:03:09.680 回答
3

您只需将服务帐户用户添加为项目的编辑器

要添加的服务帐户的电子邮件看起来像这样 {project-name}@{project-name}.iam.gserviceaccount.com

于 2016-10-26T15:34:49.790 回答
3

I did a mix of all of your suggestions, plus I needed to use the non 'obsolete' ID of the Project. When I publish the script, it gives me an ID, which I was using succesfully as long as owner runs the routine, and only within Google Chrome (If I try it on Edge it fails). When I publish and try it with a different user it stop working. I open the script, go to file / Project properties and copy the longer Script ID instead. The routine start working for any user then. In the following image I underscore in red the key that Works for developer alone, and in Green the key that Works for all users (they're cutted in purpouse, and my environment is in spanish so actual translated options may vary, sorry)

Project properties keys

I believe it is worth to make a summary:

  1. I follow intructions at 'Using the execution API' and quickstarts to publish my script as execution API. (Create the script, enable Google Apps Script Execution API, publish as API executable with Access by everybody)enter image description here
  2. I made the script visible fro everybody, on File / Sharing: API sharing settings
  3. I made sure that devMode was not set true on my call. Here the JavaScript call snipet: JavaScript call snippet
  4. I made sure that all of the scopes in the Project were included during the OAuth request: API scopes API OAuth call
  5. I have to wait a few minutes to get all security rights to get ready (i.e. OAuth credentials)

Basically, these are all the required steps I needed to follow in order to get the script up and running. Hope it helps. Finally I would like you to see what I saw when it failed and when it succeeded:API call fail API call success

Thank you!

于 2017-06-15T19:04:40.613 回答
1

I've also faced with the error and everything were associated accordantly... After some time of investigation I found out that sheet should be shared by link. This is a limitation of googleapis v4.

于 2017-04-04T13:51:38.303 回答
0

我有同样的权限问题,我通过将我的谷歌表格的状态更改为公开来解决它。现在我可以使用 GET 方法读取数据

于 2016-06-17T05:39:07.960 回答