使用服务账号认证调用Google My Business API获取位置及评论遇阻求助
Google My Business API服务账号调用问题解决方案
核心问题定位
你当前获取到的账号是PERSONAL类型且未验证,这类账号本身没有商家位置数据,所以调用位置接口会返回空或404。服务账号默认生成的个人账号无法直接访问商家数据,必须先关联到实际的商家管理账号。
分步解决方案
1. 关联服务账号到商家账号
- Google Workspace用户:在Admin控制台为服务账号配置域范围委派,授予
https://www.googleapis.com/auth/business.manage等必要权限,确保服务账号能代表商家账号操作。 - 非Workspace用户:登录Google My Business后台,将服务账号的邮箱添加为商家账号的管理员,赋予其管理位置和评论的权限。
2. 修正位置查询接口
- 使用My Business Information API的正确端点,且必须使用商家账号的ID(不是服务账号自身的个人账号ID)。
readMask参数需指定有效字段,避免仅传name导致的字段缺失问题。
修正后的代码示例:
// 替换{商家账号ID}为实际绑定的商家账号ID const locationsUrl = `https://mybusinessinformation.googleapis.com/v1/accounts/{商家账号ID}/locations?readMask=name,title,address,storeCode`; const locationsRes = await client.request({ url: locationsUrl }); console.log(locationsRes.data);
3. 获取商家评论的正确方式
评论接口需调用My Business Business Information API,传入位置ID和指定评论字段的readMask:
// 替换{商家账号ID}和{位置ID}为实际值 const reviewsUrl = `https://mybusinessbusinessinformation.googleapis.com/v1/accounts/{商家账号ID}/locations/{位置ID}/reviews?readMask=name,reviewer.displayName,rating,comment.text`; const reviewsRes = await client.request({ url: reviewsUrl }); console.log(reviewsRes.data);
4. 权限与API确认
- 确保已启用所有必要API:
My Business Account Management API、My Business Information API、My Business Business Information API。 - 服务账号的scopes保持
https://www.googleapis.com/auth/business.manage即可,无需重复添加旧的plus.business.manage。
内容的提问来源于stack exchange,提问作者shakir ullah
相关产品推荐
相关产品推荐

