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

调用Google My Business API获取地点评论时出现Error 404问题

Google My Business评论接口404错误排查方案

核心排查方向:

  • locationName格式不合法
    accounts.locations.reviews.list接口要求locationName必须是完整的资源路径,格式为accounts/{account_id}/locations/{location_id}。如果你的locationName仅传入了地点ID(比如123456),缺少accounts/{account_id}/前缀,接口会因找不到对应资源返回404。
    正确的URL构造示例:

    String baseUrl = "https://mybusiness.googleapis.com/v4/accounts/your_account_id/locations/your_location_id/reviews";
    
  • 权限不足导致的伪装404
    Google API存在权限不足时返回404而非403的情况,请确认:

    • 授权时请求的scope包含https://www.googleapis.com/auth/business.manage
    • 生成Credential的账号是目标地点的所有者或管理员,拥有访问权限
  • URL拼接与编码问题

    • 如果locationName包含特殊字符(如空格、特殊符号),需对其进行URL编码,避免路径解析错误
    • 分页拼接pageToken时,若后续需添加其他参数,需改用&拼接,但当前代码逻辑(首次无参数时用?)是正确的,此问题概率较低
  • 端点拼写错误
    确认API端点无拼写错误,比如是否误写为mybusiness.google.com(缺少apis后缀),或路径中的reviews是否拼写正确

代码优化建议

可在函数开头添加格式校验,提前拦截非法参数:

public static JSONArray FetchReview(String hostname, String locationName) throws Exception {
    // 新增格式校验,匹配accounts/数字/locations/数字的格式
    if (!locationName.matches("accounts/\\d+/locations/\\d+")) {
        throw new IllegalArgumentException("locationName格式错误,需为accounts/{accountId}/locations/{locationId}");
    }
    
    JSONArray finalReviews = new JSONArray();
    // 后续原有代码...
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 19:55:16