Google Sheets API 返回“调用者没有权限"使用服务器密钥时 [英] Google Sheets API returns "The caller does not have permission" when using server key
本文介绍了Google Sheets API 返回“调用者没有权限"使用服务器密钥时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 API 管理器中生成了一个服务器密钥并尝试在我的 Mac 上执行以下操作:
I've generated a server key in the API Manager and attempted to execute the following on my Mac:
curl 'https://sheets.googleapis.com/v4/spreadsheets/MySheetID?ranges=A1:B5&key=TheServerKeyIGeneratedInAPIManager'
但这就是它返回的内容:
But this is what it returns:
{
"error": {
"code": 403,
"message": "The caller does not have permission",
"status": "PERMISSION_DENIED"
}
}
我在这里做错了什么?
推荐答案
要解决此问题,请尝试:
To solve this issue, try to:
- 创建服务帐户:https://console.developers.google.com/iam-admin/serviceaccounts/
- 在选项中,创建一个密钥:此密钥是您常用的 client_secret.json - 以相同的方式使用
- 为服务帐户设置角色所有者(成员名称 = 服务帐户 ID = 服务帐户电子邮件,例如:thomasapp@appname-201813.iam.gserviceaccount.com
- 复制您的服务帐号的电子邮件地址 = 服务帐号 ID
- 只需在浏览器中转到您要与之交互的 Google 表格
- 转到屏幕右上角的共享"
- 转到高级设置并与您的服务帐户的电子邮件地址共享,例如:thomasapp@appname-201813.iam.gserviceaccount.com
这篇关于Google Sheets API 返回“调用者没有权限"使用服务器密钥时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文