错误:在使用TypeScript的Google REST API列出成员时找不到Google Chat应用程序。

huangapple go评论98阅读模式
英文:

Error: Google Chat app not found while listing members using Google REST API in TypeScript

问题

我正在尝试使用我的TypeScript后端从Google REST API列出Google Chat空间的成员。目前,我在实现此功能时遇到困难,以下是我的代码:

const { google } = require('googleapis');

async function authenticate() {
  const auth = new google.auth.GoogleAuth({
    keyFile: './pmtest-112533-5b83338226fd.json',
    scopes: ['https://www.googleapis.com/auth/chat.spaces'],
  });

  return await auth.getClient();
}

async function getSpacesList() {
  const client = await authenticate();

  const chat = google.chat({ version: 'v1', auth: client });

  return await chat.spaces.list();
}

getSpacesList()
  .then(response => {
    console.log('response:', response.data);
  })
  .catch(error => {
    console.error('Error:', error);
  });

并且我收到以下错误消息:

GaxiosError: 找不到Google Chat应用程序。要创建Chat应用程序,您必须打开Chat API并在Google Cloud控制台中配置该应用程序。

问题可能是什么?

英文:

I am trying to list members of a Google Chat space using the Google REST API from my TypeScript backend. Currently, I am facing difficulties in implementing this functionality, this is my code:

const { google } = require('googleapis');

async function authenticate() {
  const auth = new google.auth.GoogleAuth({
    keyFile: './pmtest-112533-5b83338226fd.json',
    scopes: ['https://www.googleapis.com/auth/chat.spaces'],
  });

  return await auth.getClient();
}

async function getSpacesList() {
  const client = await authenticate();

  const chat = google.chat({ version: 'v1', auth: client });

  return await chat.spaces.list();
}

getSpacesList()
  .then(response => {
    console.log('response:', response.data);
  })
  .catch(error => {
    console.error('Error:', error);
  });

and I have this error message:

GaxiosError: Google Chat app not found. To create a Chat app, you must turn on the Chat API and configure the app in the Google Cloud console.

What could be the problem?

console.google screenshot

答案1

得分: 0

错误消息非常明确。在尝试访问他们的API之前,您需要启用Chat API并在Google Cloud控制台中配置应用程序。

要启用Chat API,您可以访问以下链接:

https://console.cloud.google.com/flows/enableapi?apiid=chat.googleapis.com

此外,您需要一个具有访问Google Chat权限的Google Workspace帐户。Google Chat API不适用于免费的Google帐户(Gmail)。

还请确保您的凭据正确,并与已启用Google Chat API的项目相关联。

英文:

The error message is very clear. You need to turn on the Chat API and configure the app in the Google Cloud console before trying to hit their API.

To enable the Chat API, you can visit the following link:

https://console.cloud.google.com/flows/enableapi?apiid=chat.googleapis.com

Additionally, you need a Google Workspace account with access to Google Chat. The Google Chat API will not work with a free Google account (Gmail).

Also, please ensure that your credentials are correct and associated with the project that has already enabled the Google Chat API.

huangapple
  • 本文由 发表于 2023年7月14日 02:20:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76682243.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定