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

使用google-ads-api传入正确customer_id仍报Invalid Customer ID错误

报错原因
  • 报错返回的无效客户ID是空字符串'',说明你传入的客户ID参数没有被模块正确读取,并非ID格式本身不合法,而是模块没有接收到有效值
  • google-ads-api模块仅接受无连字符的10位纯数字格式的customer_id,你传入的带连字符格式不会被自动解析,部分版本会直接过滤为无效空值
  • 不同版本的google-ads-api对客户ID的参数名要求不一致,部分旧版本要求使用驼峰格式customerId,如果你用了下划线格式customer_id会导致参数识别失败,传入值被忽略
解决方法
  • 先处理客户ID格式,把所有-分隔符删除,仅保留10位纯数字,例如XXX-XXX-XXXX处理为'XXXXXXXXXX'
  • 优先尝试使用驼峰格式的参数名customerId,示例代码如下:
const customer = client.Customer({
    customerId: 'XXXXXXXXXX', // 替换为你的10位纯数字客户ID
    refresh_token: refreshToken,
})
  • 构造实例前先打印你传入的客户ID值,确认该变量本身不是空值或者undefined:
// 先校验传入的ID是否有效
const rawCustomerId = 'XXX-XXX-XXXX'
const cleanedCustomerId = rawCustomerId.replace(/-/g, '')
console.log('处理后的客户ID:', cleanedCustomerId) // 确认此处输出为10位纯数字

const customer = client.Customer({
    customerId: cleanedCustomerId,
    refresh_token: refreshToken,
})
  • 确认当前使用的refresh_token对应的Google账号,具备你传入的客户ID对应广告账户的访问权限,且该广告账户已经开通Google Ads API访问权限

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.06 19:00:01