使用php获取谷歌分析实时数据
作者:互联网
我想为活跃用户获取谷歌分析实时数据.我用过google api client php
https://code.google.com/p/google-api-php-client/source/browse/trunk/src/?r=474#
For screenviews after setting metrics and dimensions
$metrics = 'ga:screenviews';
$optParams = array('dimensions' => 'ga:screenName');
$service = new Google_AnalyticsService($client);
try {
$result = $service->data_ga->get(
$GA_VIEW_ID,
$start_date,
$end_date,
$metrics,
$optParams
);
} catch(Exception $e) {
var_dump($e);
}
我得到了正确的结果.
我想获得实时数据但无法获得它.我试过如下.
$metrics =’rt:medium’;
$optParams = array(‘dimensions’=>’rt:activeUsers’);
try {
$results = $service->data_realtime->get(
$GA_VIEW_ID,
'rt:activeUsers',
$optParams);
} catch (apiServiceException $e) {
// Handle API service exceptions.
$error = $e->getMessage();
}
// Error : Undefined property: Google_AnalyticsService::$data_realtime
请给我解决方案以获取实时数据.
解决方法:
问题是您签出了一个非常旧版本的客户端库.继续从github检出v1-master分支:
git clone -b v1-master https://github.com/google/google-api-php-client.git
我还建议按照Hello Analytics API php中的说明来帮助您入门.
标签:php,google-api,google-analytics-api,google-api-php-client 来源: https://codeday.me/bug/20190711/1432954.html