我一直在关注Hello Analytics Reporting API v4; PHP quickstart for service accounts为了完成从谷歌分析报告中获取数据的 API 的设置。
在创建服务帐户、下载私钥和安装客户端库时,我已经完成了前三个步骤。我将私钥 JSON 文件放在与 HelloAnalytics.php
相同的目录中我从该站点获得的示例文件。我使用了在分析事件的 View 设置中找到的 view_id。然后我更改了$KEY_FILE_LOCATION
到私钥文件的名称。
出于某种原因,当我运行示例分析文件时,我收到一个 403 错误,提示权限已被拒绝,即使我已在事件管理员内添加了 API 权限。
我跳过了一步吗?可能出了什么问题?
最佳答案
是的,你错过了一步。服务帐号必须经过预授权。
Add service account to the Google Analytics account
The newly created service account will have an email address that looks similar to:
quickstart@PROJECT-ID.iam.gserviceaccount.com
Use this email address to add a user to the Google analytics view you want to access via the API. For this tutorial only Read & Analyze permissions are needed.
转到管理部分的 Google 分析网站,并将服务帐户电子邮件地址添加为用户。在帐户级别。
关于php - 从谷歌分析 api 获取数据的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43796066/