php - GAPI : Failed to request report data. 错误:“GDatainsufficientPermissionsUser 对此配置文件没有足够的权限

标签 php google-analytics-api

我在获取谷歌分析报告时遇到以下错误

“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 &amp; 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/

相关文章:

google-analytics - 未使用 Google Analytics gigi 获取目标名称

google-analytics - Google Analytics API 上的每日/每周/每月活跃用户数

python - Google Analytics API - 我可以使用自己的 Google 帐户向其他人显示报告吗?

php - 保持 MySQL 数据库与外部源 (.csv) 同步,同时维护以前的数据

php - 修复 Laravel 表单数组验证递归限制

php - 如何自动加载 smarty 插件

windows-phone-7 - Google OAuth API 不再工作了?! 404错误

php - MySQL GROUP BY 返回一行

php - 警告 : file_get_contents(): https://wrapper is disabled in the server configuration by all

php - GAPI-Google Analytics(分析)采样。