简体   繁体   English

从Google Analytics API提取数据时出现问题

[英]Issue fetching data from google analytics api

I've been following Hello Analytics Reporting API v4; 我一直在关注Hello Analytics Reporting API v4; PHP quickstart for service accounts in order to complete the set up for an API that will get data from a Google Analytics Report. 服务帐户的PHP快速入门,以完成API的设置,该API将从Google Analytics(分析)报告中获取数据。

I've completed the first three steps as I created the service account, downloaded the private key, and installed the client library. 创建服务帐户,下载私钥并安装客户端库时,我已经完成了前三个步骤。 I put the private key JSON file in the same directory as the HelloAnalytics.php sample file I got from the site. 我将私钥JSON文件与从站点获得的HelloAnalytics.php示例文件放在同一目录中。 I used the view_id that is found in the view settings for the analytics campaign. 我使用了在分析活动的视图设置中找到的view_id。 I then changed the $KEY_FILE_LOCATION to the name of the private key file. 然后,我将$KEY_FILE_LOCATION更改为私钥文件的名称。

For some reason, when I run sample analytics file, I get the a 403 error saying that permission has been denied even though I have added permission for the API inside of the campaign admin. 出于某种原因,当我运行示例分析文件时,我收到403错误消息,即使我在广告系列管理员中添加了对该API的许可,该许可也被拒绝。

Did I skip a step? 我跳过了一步吗? What could be going wrong? 可能出什么问题了?

Yes you have missed a step. 是的,您错过了一步。 Service accounts must be preauthorized. 服务帐户必须经过预授权。

Add service account to the Google Analytics account 将服务帐户添加到Google Analytics(分析)帐户

The newly created service account will have an email address that looks similar to: 新创建的服务帐户将具有一个类似于以下内容的电子邮件地址:

quickstart@PROJECT-ID.iam.gserviceaccount.com 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. 使用此电子邮件地址将用户添加到您要通过API访问的Google Analytics(分析)视图中。 For this tutorial only Read & Analyze permissions are needed. 对于本教程,仅需要“读取和分析”权限。

Go to the Google analytics website in the admin section and add the service account email address as a user. 转到管理部分的Google Analytics(分析)网站,然后以用户身份添加服务帐户的电子邮件地址。 At the ACCOUNT level. 在帐户级别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM