未找到 Google 聊天应用程序。要创建聊天应用,您必须启用 Chat API 并在 Google Cloud 控制台中配置该应用。 python 中的错误

问题描述 投票:0回答:1

我正在尝试访问聊天 API 来创建空间、群组、发送消息以及为 odoo 添加附件。现在,当我在 python 中尝试它时,即使我遵循了 google 和社区建议的每个步骤,我还是收到 403 或 404 错误,指出

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.
我遵循的步骤。

  1. 在 GCP 中创建项目
  2. 通过转至项目 > API 和服务 > 启用的 API 和服务 > 谷歌聊天 API > 启用来启用 API
  3. 启用后,我会看到管理它的按钮,“管理”>“凭据”>“创建凭据”>“服务帐户”。
  4. 进入服务屏幕后,我添加名称、授予角色(所有者、聊天机器人所有者)> 完成。
  5. 创建服务帐户后,> 密钥 > 添加新密钥 > 下载 json 并使用它。

遵循上述所有步骤后,我确信我正在启用 API 并正确使用其密钥,但不知道它再次提示聊天应用程序未找到。

我想使用服务帐户对其进行授权,因为我正在尝试在组织级别集成它。

下面是我正在使用的代码

from googleapiclient.discovery import build
from google.oauth2 import service_account

# Replace with your service account key file path
SERVICE_ACCOUNT_KEY_FILE = "./fluted-bee-418112-d595ff244760.json"

# Scopes for Chat API access
SCOPES = ['https://www.googleapis.com/auth/chat.bot', "https://www.googleapis.com/auth/chat.spaces.create", "https://www.googleapis.com/auth/chat.messages"] # "https://www.googleapis.com/auth/chat.spaces", "https://www.googleapis.com/auth/chat.spaces.create", 

def create_space(credentials, name):
    service = build("chat", "v1", credentials=credentials)
    print(service)
    body = {
        "displayName": name,
        "spaceType": "SPACE",
    }
    try:
        response = service.spaces().create(body=body).execute()
        print(f"Space created: {response['name']}")
        # return response["name"]

    except Exception as e:
        print(f"Error creating space: {e}")
        return None

def get_service_account_credentials():

    credentials = service_account.Credentials.from_service_account_file(
                              filename=SERVICE_ACCOUNT_KEY_FILE, 
                              scopes=SCOPES)

    return credentials

if __name__ == "__main__":
    # Get credentials using service account
    credentials = get_service_account_credentials()

    # Create space using authorized credentials
    space_name = create_space(credentials, "My Space")
    if not space_name:
        exit()


完全错误

<googleapiclient.discovery.Resource object at 0x00000151E77DD5B0>
Error creating space: <HttpError 404 when requesting https://chat.googleapis.com/v1/spaces?alt=json returned "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.". Details: "[{'@type': 'type.googleapis.com/google.rpc.Help', 'links': [{'description': 'To turn on the Google Chat API, go to the Google Chat API page in the Google Cloud console and click Enable.', 'url': 'https://console.cloud.google.com/marketplace/product/google/chat.googleapis.com'}]}, {'@type': 'type.googleapis.com/google.rpc.Help', 'links': [{'description': 'To configure your Chat app, go to the Google Chat API Configuration tab in the Google Cloud console.', 'url': 'https://console.cloud.google.com/apis/api/chat.googleapis.com/hangouts-chat'}]}, {'@type': 'type.googleapis.com/google.rpc.Help', 'links': [{'description': 'To learn about creating Google Chat apps, visit the documentation.', 'url': 'https://developers.google.com/chat'}]}]">
google-cloud-platform chatbot google-chat
1个回答
0
投票

我不确定您是否还配置了 ChatAPI,但忘记在这里提及。但如果你还没有,你就需要这样做。 为此,请转至 Google Chat API,然后单击管理 > 配置。并使用this作为参考。

© www.soinside.com 2019 - 2024. All rights reserved.