使用Python调用Google Analytics v4 API遇403权限不足问题求助
调用Google Analytics v4 API时遭遇403权限错误(服务账号场景)
错误详情
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://analyticsreporting.googleapis.com/v4/reports:batchGet?alt=json returned "User does not have sufficient permissions for this profile.". Details: "User does not have sufficient permissions for this profile.">
场景说明
使用**服务账号(Service Account)**进行API调用
服务账号创建流程
- 进入Google Cloud Console;
- 创建仅用于该API的新项目;
- 启用
Analytics Reporting API、Google Analytics Admin API、Google Analytics Data API和Google Analytics API; - 进入
Credentials页面创建新服务账号; - 为其配置相应凭据;
- 在
Domain-wide Delegation中添加作用域; - 将服务账号邮箱(xxxxx@xxxxx.iam.gserviceaccount.com)添加为Google Analytics控制台管理员。
已尝试的解决方法
- 将服务账号邮箱添加为Analytics控制台管理员;
- 在Google Cloud的Domain-wide Delegation中添加作用域;
- 查阅Google官方文档;
- 更换其他拥有凭据的服务账号.json文件,仍无效;
- 遵循Google官方教程步骤操作,仍无效;
- 更换其他VIEW_ID,仍无效。
补充说明
Google API显示服务已初始化,但无法获取数据,返回403错误。已查阅StackOverflow相关问答,未找到有效解决方案。
内容的提问来源于stack exchange,提问作者ytpm
相关产品推荐
相关产品推荐

