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

如何通过已获取的access_token获取Google客户账户完整详情(Node.js)

使用Google Ads API获取客户账户完整详情(Node.js)

核心解决思路

要获取客户账户的完整信息,不能仅停留在获取ID列表,需调用Google Ads API的CustomerService接口,通过getCustomer方法或自定义search查询来拉取多维度字段数据。

具体实现步骤

1. 确认依赖与授权配置

先确保已安装官方Google Ads API依赖:

npm install google-ads-api

授权环节需注意:

  • access_token必须包含https://www.googleapis.com/auth/adwords权限
  • 提前准备好目标账户的clientCustomerId(格式为xxx-xxx-xxxx)
  • 配置好有效的开发者令牌(developer_token)

2. 代码实现:获取完整账户信息

const { GoogleAdsApi } = require('google-ads-api');

// 初始化API客户端
const client = new GoogleAdsApi({
    client_id: '你的客户端ID',
    client_secret: '你的客户端密钥',
    developer_token: '你的开发者令牌',
});

async function fetchFullCustomerDetails(clientCustomerId) {
    try {
        // 初始化客户实例
        const customer = client.Customer({
            customer_id: clientCustomerId,
            refresh_token: '你的刷新令牌', // 也可直接传入有效的access_token
        });

        // 获取账户基础核心信息
        const basicDetails = await customer.get();
        console.log('账户基础信息:', basicDetails);

        // 自定义查询获取更多字段(按需调整SELECT内容)
        const detailedQuery = `
            SELECT 
                customer.id,
                customer.descriptive_name,
                customer.currency_code,
                customer.time_zone,
                customer.tracking_url_template,
                customer.auto_tagging_enabled,
                customer.address,
                customer.manager
            FROM customer
        `;
        const [detailedResults] = await customer.search(detailedQuery);
        console.log('账户完整详情:', detailedResults);
    } catch (error) {
        console.error('获取账户详情失败:', error.message);
    }
}

// 调用示例(替换为目标账户ID)
fetchFullCustomerDetails('123-456-7890');

3. 常见问题排查

  • 权限报错:检查OAuth授权时是否申请了adwords权限,开发者令牌是否与目标账户关联
  • 格式错误:clientCustomerId必须严格使用xxx-xxx-xxxx格式,不能省略分隔符
  • 字段缺失:确认使用的Google Ads API版本为当前稳定版(如v15),避免旧版本不支持部分字段

扩展说明

如果需要获取账户关联的其他资源(如广告系列、关键词),可扩展search语句,加入对应资源表即可,例如关联campaign表查询账户下的广告系列数据。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 18:05:49