Bha*_*iya 2 php google-analytics-api
我在获取Google Analytics分析报告时遇到以下错误
"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>
Run Code Online (Sandbox Code Playgroud)
Raf*_*med 16
您的个人资料ID可能有误!不要弄乱配置文件ID和帐户ID.两者都不一样!
只需登录您的Google Analytics帐户,然后点击"管理"标签转到设置,如果您注意到网址.它将如下所示
https://www.google.com/analytics/web/?hl=en#management/Settings/a46773936w11870770pxxxxxxxx/
Run Code Online (Sandbox Code Playgroud)
在字母"p"之后,您将获得8位数字.那是你的个人资料ID号.
注意:由于谷歌界面和框架现在变化太快,这个解决方案仅适用于当前界面,我无法保证它将来会有效.
| 归档时间: |
|
| 查看次数: |
3176 次 |
| 最近记录: |