我在获取谷歌分析报告时遇到以下错误
“GAPI:请求报告数据失败。错误:“GDatainsufficientPermissionsUser 没有足够的权限访问此配置文件。”
示例代码如下所示。
<?php
define('ga_email','test@gmail.com');
define('ga_password','test');
define('ga_profile_id','999999999');
require 'gapi.class.php';
$ga = new gapi(ga_email,ga_password);
$ga->requestReportData(ga_profile_id,array('firefox','25.0.1'),array('pageviews','visits'));
?>
<table>
<tr>
<th>Browser & Browser Version</th>
<th>Pageviews</th>
<th>Visits</th>
</tr>
<?php
foreach($ga->getResults() as $result):
?>
<tr>
<td><?php echo $result ?></td>
<td><?php echo $result->getPageviews() ?></td>
<td><?php echo $result->getVisits() ?></td>
</tr>
<?php
endforeach
?>
</table>
<table>
<tr>
<th>Total Results</th>
<td><?php echo $ga->getTotalResults() ?></td>
</tr>
<tr>
<th>Total Pageviews</th>
<td><?php echo $ga->getPageviews() ?>
</tr>
<tr>
<th>Total Visits</th>
<td><?php echo $ga->getVisits() ?></td>
</tr>
<tr>
<th>Results Updated</th>
<td><?php echo $ga->getUpdated() ?></td>
</tr>
</table>
最佳答案
您的个人资料 ID 可能有误!不要混淆配置文件 ID 和帐户 ID。两者不同!
只需登录您的 Google Analytics(分析)帐户,然后点击“管理”标签进入设置 如果您注意到 URL 地址。会像下面这样
https://www.google.com/analytics/web/?hl=en#management/Settings/a46773936w11870770pxxxxxxxx/
在字母“p”之后,您将获得 8 位数字。那是您的个人资料 ID 号。
注意:由于现在 google 界面和框架变化太快,此解决方案仅适用于当前界面,我不能保证它会在未来工作。
关于php - GAPI : Failed to request report data. 错误:“GDatainsufficientPermissionsUser 对此配置文件没有足够的权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20691967/