我正在尝试使用nodejs库访问谷歌经销商 api,该库非常糟糕……,我的意思是参差不齐的文档。我尝试按照此处的示例进行操作,但在第 3 步失败并出现以下错误:
code: 403,
errors: [
{
domain: 'global',
reason: 'insufficientPermissions',
message: 'Authenticated user is not authorized to perform this action.'
}
]
我的配置如下所示:
const OAUTH2_SCOPES = [
"https://www.googleapis.com/auth/admin.directory.user",
"https://www.googleapis.com/auth/apps.order",
"https://www.googleapis.com/auth/siteverification",
"https://www.googleapis.com/auth/cloud-platform",
];
const authJWT = new google.auth.JWT({
keyFile: JSON_PRIVATE_KEY_FILE,
scopes: OAUTH2_SCOPES,
subject: RESELLER_ADMIN_USER,
email: "gsuite-reseller@some-cool-name-because-why-not.iam.gserviceaccount.com",
});
使用基本的 google fu,我找到了这个线程,这表明我的问题与模仿有关。所以我用我的帐户电子邮件交换了subject
财产中的电子邮件,该电子邮件具有指定的所有者权利。我还授予了服务帐户所有者权限,因为那时我很无知。不幸的是,这仅将错误消息更改为:
status: 401,
statusText: 'Unauthorized'
有人知道出了什么问题吗?401表明缺少凭据。除了服务帐户之外,我是否还必须指定我的私人电子邮件凭据?如果是,那么在哪里?我没有在该google.auth.JWT.options
物体上找到任何听起来很有希望的属性。