【发布时间】:2020-07-21 09:54:23
【问题描述】:
const { google } = require('googleapis')
const privatekey = require('./a.json')
const scopes = ['https://www.googleapis.com/auth/chat.bot'];
const a = async () => {
try {
const jwtClient = new google.auth.JWT(
privatekey.client_email,
null,
privatekey.private_key,
scopes,
'adminEmail@org.com'
);
await jwtClient.authorize();
const chat = google.chat({ version: 'v1', auth: jwtClient });
const res = await chat.spaces.messages.get({name:'spaces/XXX/messages/XX.XX'})
console.log(res)
}
catch(e) {
console.log(e)
}
}
a()
错误:请求包含无效参数
我找不到无效的参数
提前致谢
【问题讨论】:
-
如果您使用
'https://www.googleapis.com/auth/chat代替scopes,是否可以解决问题?是 JWT 客户端的构建还是chat.spaces.messages.get给你的错误? -
是的,我试过了它说“权限不足”我还在域范围的委派中添加了
https://www.googleapis.com/auth/chat。我正在创建一个机器人,它试图从已经安装它的房间获取消息 -
“权限不足”表示您没有为域范围的委托授权必要的范围(
https://www.googleapis.com/auth/chat而不是https://www.googleapis.com/auth/chat.bot)。每次更改范围时不要忘记删除令牌文件。https://www.googleapis.com/auth/chat.bot只能用于没有模拟的服务帐户。见here。 -
请注意,对于某些请求,service account is required。这意味着没有模拟的服务帐户。
-
@ziganotschka 是的,谢谢它用于获取消息,只需要创建一个新的 API 密钥,但现在可以从聊天机器人中删除消息,有 API,但聊天机器人只能删除它发送的消息,而不是其他用户发送的消息。
标签: google-api google-workspace hangouts-api