Google My Business API获取评论时遇PERMISSION_DENIED错误求助
解决Google My Business API获取评论时的PERMISSION_DENIED问题
问题概述
已配置OAuth 2.0 Playground及基于Google.Apis.MyBusinessAccountManagement.v1的C#代码,目标是获取商家评论列表,但该库无评论相关方法。直接调用端点https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews,搭配https://www.googleapis.com/auth/business.manage和https://www.googleapis.com/auth/plus.business.manage权限时,出现403 PERMISSION_DENIED错误,提示API未启用或未使用过,但已完成项目关联商家流程且API已启用(附截图)。
错误信息:
{ "error": { "status": "PERMISSION_DENIED", "message": "Google My Business API 尚未在项目 {projectId} 中使用过或已被禁用。请访问对应控制台页面启用后重试。如果刚启用此API,请等待几分钟让操作同步到系统后重试。", "code": 403, "details": [ { "@type": "type.googleapis.com/google.rpc.Help", "links": [ { "url": "对应控制台API激活链接", "description": "Google开发者控制台API激活" } ] }, { "reason": "SERVICE_DISABLED", "@type": "type.googleapis.com/google.rpc.ErrorInfo", "domain": "googleapis.com", "metadata": { "consumer": "projects/{projectId}", "service": "mybusiness.googleapis.com" } } ] } }
截图:
解决方案
1. 确认API启用与项目匹配
- 核对报错中的
{projectId}是否与你启用API的项目ID完全一致,避免OAuth Playground选错项目或关联商家的项目与启用API的项目不匹配。 - 强制重置API状态:先禁用My Business API,等待1-2分钟后重新启用,再等待5-10分钟让权限同步(Google API权限同步存在延迟)。
2. 修正权限范围
- 调用评论接口仅需
https://www.googleapis.com/auth/business.manage权限,plus.business.manage为旧版弃用权限,在OAuth 2.0 Playground中移除该权限,重新获取授权令牌后重试。
3. 使用正确的C#库调用评论接口
Google.Apis.MyBusinessAccountManagement.v1库仅负责账号管理,评论相关接口需使用**Google.Apis.MyBusinessReviews.v1(旧版)或Google.Apis.MyBusinessBusinessInformation.v1**(新版整合库)。示例代码:
// 加载凭证并初始化服务 var credential = GoogleCredential.FromFile("你的凭证文件路径.json") .CreateScoped(MyBusinessReviewsService.Scope.BusinessManage); var service = new MyBusinessReviewsService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "你的应用名称" }); // 构造评论列表请求 var reviewsRequest = service.Accounts.Locations.Reviews.List("accounts/{accountId}/locations/{locationId}"); // 执行请求获取结果 var reviewsResponse = reviewsRequest.Execute();
4. 验证商家关联与账号权限
- 确认授权用的Google账号是目标商家的所有者或管理员,普通员工账号无评论读取权限。
- 检查项目是否已通过商家关联审核:即使提交了关联表单,需确保Google已审核通过,可在Google Business Profile后台确认项目关联状态。
内容的提问来源于stack exchange,提问作者Leonardo Tanoue
相关产品推荐
相关产品推荐

