错误:呼叫者没有节点中Google聊天机器人的权限

时间:2020-10-09 05:59:53

标签: node.js google-api-nodejs-client hangouts-chat

尝试向Google聊天室发送消息时,我不断收到错误消息“呼叫者没有权限”。我已将漫游器添加到会议室中,并且可以列出会议室(请参见console.log),因此我知道我的凭据已加载且有效。另外,我要发送到的房间在console.log中返回的房间列表中。不确定是什么问题。

import { Auth, chat_v1 } from "googleapis";

const postMessage = async (message: string) => {
  const roomId = '<myroom>';

  let jwtClient = new Auth.GoogleAuth({
    keyFile: './googlekeys.json',
    scopes: ['https://www.googleapis.com/auth/chat.bot']
  });
  const chat = new chat_v1.Chat({ auth: jwtClient });
  const rooms = await chat.spaces.list();
  rooms.data.spaces?.map((s) => {
    console.log(s);
  });
  await chat.spaces.messages.create({
    parent: `spaces/${roomId}`,
    requestBody: {
      text: message,
    }
  });
}

我的googlekeys.json文件格式:

{
  "type": "service_account",
  "project_id": "<project_id>",
  "private_key_id": "<private_key_id>",
  "private_key": "-----BEGIN PRIVATE KEY-----\<key>\n-----END PRIVATE KEY-----\n",
  "client_email": "<client_email>",
  "client_id": "<client_id>",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/starting-account-<account>"
}

0 个答案:

没有答案