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

使用Google NodeJS客户端调用Google My Business API列示账户报错如何解决

问题解决思路

错误原因

你遇到的报错是因为Google官方Node.js客户端库调用任意API时,都必须显式指定API版本,你调用google.mybusinessaccountmanagement()时未传入版本参数,直接触发了参数校验错误。

修复步骤

  • 先确认前置配置:Google Cloud项目已启用My Business Account Management API,OAuth2授权时已添加https://www.googleapis.com/auth/business.manage权限scope
  • API初始化时传入版本参数,接口调用无查询参数时需传入空对象作为入参,避免旧版本客户端的参数校验异常

修正后代码

async fetchGoogleMyBusinessAccounts() {
    console.log(`Fetching GMB Accounts`);
    let authCredentials= ...
    const oauth2Client = initOAuth2Client(platform, authCredentials);
    google.options({ auth: oauth2Client });
    // 修复点1:初始化时指定API版本
    let gmbAccountManagement = google.mybusinessaccountmanagement({
        version: 'v1'
    });
    try {
        // 修复点2:无查询参数时传入空对象作为入参
        let myBusinessAccounts = await gmbAccountManagement.accounts.list({});
        console.log(`Connected Accounts = ${JSON.stringify(myBusinessAccounts, null, 2)}`);
    } catch (e) {
        console.log(`Error Listing GMB Accounts`, e);
    }
}

其他排查点

  • 确认initOAuth2Client返回的是合法OAuth2Client实例,持有的access token/refresh token有效且未过期
  • 若使用拆分版Google API客户端,需先安装对应依赖:npm install @googleapis/mybusinessaccountmanagement
  • 若调用后返回403权限错误,检查当前授权的Google账号确实具备对应GMB商家的管理权限

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.28 23:30:01