You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否无需Google Cloud Console创建Chat App,使用服务账号调用Google Chat API?

关于Google Chat API服务账号调用的问题解答

核心结论

不行,必须通过Google Cloud Console创建并配置Chat App,才能使用服务账号调用Google Chat API。

错误原因说明

你收到的错误信息翻译为:

未找到Google Chat应用。要创建Chat应用,你必须在Google Cloud Console中启用Chat API并配置应用。

Google Chat API的所有请求都需要关联一个合法注册的Chat App,这个App是在Cloud Console中创建的身份标识,没有它API无法识别请求的合法性,因此会直接拒绝访问。

解决步骤

  • 启用Chat API:登录Google Cloud Console,进入你的项目,搜索并启用「Google Chat API」。
  • 配置Chat App:在Chat API的设置页面,完成应用基础配置(名称、头像等),并根据需求设置权限范围。
  • 配置服务账号权限:在Google Workspace管理员控制台中,给你的服务账号分配对应的Chat权限(如chat.spaces.readonly等),同时启用域范围授权(针对Workspace账号场景)。
  • 优化代码实现:建议使用官方Google Client Library简化认证流程,避免手动生成JWT的潜在问题,示例代码大致如下:
use Google\Client;
use Google\Service\Chat;

protected function getChatSpaces()
{
    $client = new Client();
    $credentialsPath = Storage::path('credentials.json');
    $client->setAuthConfig($credentialsPath);
    $client->addScope('https://www.googleapis.com/auth/chat.spaces');
    
    // 若需Workspace域范围授权,可模拟指定用户(按需启用)
    // $client->setSubject('user@your-domain.com');
    
    $chatService = new Chat($client);
    try {
        $spaces = $chatService->spaces->listSpaces();
        return $spaces;
    } catch (\Exception $e) {
        return ['error' => $e->getMessage()];
    }
}

内容的提问来源于stack exchange,提问作者Govind Nandaniya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 14:15:09