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

如何在Java中正确调用Business Profile Performance API?请求报错400

解决Java调用Business Profile Performance API的400错误

你的代码出现400 Bad Request是因为调用getDailyMetricsTimeSeries接口时,缺少了两个必填参数:需要获取的指标类型,以及查询的时间范围(起始日期和结束日期)。官方API要求这两个参数必须传入,否则会返回无效参数错误。

修正后的代码示例

try {
    // 指定要获取的指标,比如"ALL_VIEWS"、"WEBSITE_CLICKS"等,支持多选
    List<String> metrics = Arrays.asList("ALL_VIEWS", "WEBSITE_CLICKS");
    
    // 设置时间范围,格式为YYYY-MM-DD
    Date startDate = new SimpleDateFormat("yyyy-MM-dd").parse("2024-01-01");
    Date endDate = new SimpleDateFormat("yyyy-MM-dd").parse("2024-01-31");

    // 构建请求并添加必填参数
    BusinessProfilePerformance.Locations.GetDailyMetricsTimeSeries metricReport = 
        businessProfilePerformance.locations()
            .getDailyMetricsTimeSeries(locationName)
            .setMetrics(metrics)
            .setStartDate(startDate)
            .setEndDate(endDate);
    
    GetDailyMetricsTimeSeriesResponse response = metricReport.execute();
    
    if (!response.isEmpty()) {
        System.out.println("Response== " + response);
    }

} catch (Exception e) {
    e.printStackTrace(); // 建议用printStackTrace替代println,能查看完整错误栈信息
}

额外注意事项

  • locationName格式检查:确保locationName的格式为locations/{你的店铺ID},比如locations/1234567890,格式错误也会触发无效参数报错。
  • 指标合法性:使用官方支持的指标名称,比如ALL_VIEWS、SEARCH_VIEWS、MAP_VIEWS、DIRECTIONS_REQUESTS等,不要使用自定义名称。
  • 权限验证:确认授权账号拥有该店铺的Performance数据访问权限,权限不足通常会返回403错误,但也可能伴随参数类报错混淆判断。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 14:45:58