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

Google Business Profile Performance指标值获取:新API响应处理疑问

Business Profile Performance API 指标数值获取方法

原Google My Business V4.9 实现代码

之前使用GMB V4.9时,通过以下代码获取指标数值:

for (LocationMetrics locationMetrics : reportInsights.getLocationMetrics()) {
    List <MetricValue> metricValue = locationMetrics.getMetricValues();
    metricValue.get(0).getDimensionalValues().get(0).getValue();
}

升级到Business Profile Performance API后的获取方式

升级后API返回GetDailyMetricsTimeSeriesResponse类型响应,核心数据封装在TimeSeries对象中,以下是具体的指标数值获取逻辑:

  1. 响应结构说明

    • GetDailyMetricsTimeSeriesResponse包含一组TimeSeries列表,每个TimeSeries对应一个请求指定的指标(如网站点击量、呼叫量等)
    • 每个TimeSeries的points字段是按日期排序的指标数据点集合,每个Point包含value(指标数值)和date(对应日期)
  2. Java代码示例

// 假设response为GetDailyMetricsTimeSeriesResponse实例
for (TimeSeries timeSeries : response.getTimeSeriesList()) {
    // 获取当前指标标识,例如"WEBSITE_CLICKS"
    String metricType = timeSeries.getMetric();
    
    // 遍历单日指标数据
    for (TimeSeries.Point point : timeSeries.getPointsList()) {
        // 获取指标数值
        double value = point.getValue();
        // 获取数据对应的日期(格式为YYYY-MM-DD)
        String date = point.getDate();
        
        // 根据业务需求处理数据,示例为打印输出
        System.out.printf("指标类型: %s | 日期: %s | 数值: %.2f%n", metricType, date, value);
    }
}
  1. 注意事项
    • 如果请求时指定了多个指标,getTimeSeriesList()会返回对应数量的TimeSeries对象
    • 部分指标支持维度拆分(如流量来源),可通过TimeSeries.getDimensionsList()获取维度信息,再结合Point中的值做细分统计
    • 指标数值的类型根据指标不同可能为整数或小数,可根据实际场景做类型转换

内容的提问来源于stack exchange,提问作者Asa'd Mahajna

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 22:05:52