You need to enable JavaScript to run this app. React Native调用Google My Business API报404 Method not found错误
优惠活动
大模型
产品
解决方案
定价
更多

React Native调用Google My Business API报404 Method not found错误

报错原因排查
  • API版本已废弃:Google My Business v4版本已于2022年全面下线,旧接口根地址https://mybusiness.googleapis.com/v4/已停止服务,直接请求会返回404未找到错误。
  • 接口路径不匹配:新版本接口的根域名和路径已更新,旧的路径规则不再适用。
  • 账号ID参数错误:你传入的userId如果是普通Google账号ID,而非Google My Business专属的、带accounts/前缀的完整账号ID,会导致请求路径不合法触发404。
解决方案
  • 替换为新版本接口地址:将请求地址更换为Google My Business Business Information API v1的定位列表接口:
    https://mybusinessbusinessinformation.googleapis.com/v1/accounts/${accountId}/locations
    
    其中accountId需要先调用账号列表接口获取当前授权用户名下的GMB账号列表,拿到带accounts/前缀的完整ID后再传入,不可直接使用普通用户ID。
  • 补充必要请求参数:新接口要求必须传递readMask查询参数指定返回字段,可根据需求填写需要返回的定位属性,示例:?readMask=name,title,address,phoneNumbers,未传递该参数会直接返回请求无效错误。
  • 检查Google Cloud项目配置:确认你使用的webClientId对应的Google Cloud项目,已启用Google My Business Business Information API,未启用该API也会触发同类访问错误。
  • 修复登录逻辑代码异常:你的登录函数存在拼写错误,且.then回调内的await未声明async,修改后参考代码:
    const googleSignIn = async () => {
      try {
        await GoogleSignin.hasPlayServices();
        const userInfo = await GoogleSignin.signIn()
        if (userInfo) {
          const data = await GoogleSignin.getTokens();
          console.log('access-token:', data.accessToken);
        }
      } catch (e) {
        console.log(e)
      }
    }
    
  • 原有权限配置无需调整,https://www.googleapis.com/auth/business.manage仍适配新版本API的权限要求。

修改后的接口请求参考代码:

const getLocation = async (accountId, accessToken) => {
  if (accessToken) {
    try {
      const res = await fetch(`https://mybusinessbusinessinformation.googleapis.com/v1/accounts/${accountId}/locations?readMask=name,title,address`, {
        headers: {
          'Accept': 'application/json',
          Authorization: `Bearer ${accessToken}`,
        }
      })
      return await res.json()
    } catch (e) {
      return Promise.reject(e)
    }
  } else {
    Alert.alert('', 'Access token missing')
  }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.20 10:15:04