gpt4 book ai didi

google-api-nodejs-client - 在 Google API NodeJS 客户端中使用 getClient() 时如何模拟管理员用户

转载 作者:行者123 更新时间:2023-12-03 23:16:10 32 4
gpt4 key购买 nike

recommendation在 defaultauth 示例中,我试图访问我为其创建了服务帐户的域的目录 api。这是我试图连接的代码:

import { google } from 'googleapis'

const authClient = await google.auth.getClient({
scopes: ['https://www.googleapis.com/auth/admin.directory.user.readonly']
})

const service = google.admin('directory_v1')

console.log(
await service.users.list({
auth: authClient,
domain: <redacted>
})
)

但是,当我尝试连接时,我收到一条错误消息 Error: Not Authorized to access this resource/api .如果我删除 creds.json文件在 ~/.google ,错误变为说它找不到凭据文件。此外,我可以使用同一个文件访问存储桶,所以我很确定我的本地环境设置正确,身份验证是明智的。在过去的几天里,我还与支持团队 G Suite API 团队的某个人一起工作,他向我保证我的域上的设置正确。

在网上环顾四周后,似乎我缺少的是在尝试与我的服务帐户连接时冒充管理员帐户。我在网上找到了一些使用 JWT 身份验证策略执行此操作的示例,但我想继续使用默认身份验证客户端,以便抽象出实现细节。这可能吗?如果是这样,我需要改变什么?我试过设置 subject , 和 delegationEmail在两个调用中( getClientlist )。

任何帮助将不胜感激。

最佳答案

只需设置客户端对象的主题:

authClient.subject = 'your email address'

Google 的 api 文档因语言而异。没有标准。 PHP 客户端中记录的某些内容可能会在 nodejs 客户端中丢失,并且可能需要数小时才能找出如何执行此操作。

关于google-api-nodejs-client - 在 Google API NodeJS 客户端中使用 getClient() 时如何模拟管理员用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50335892/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com