分析API&;PHP-获取不同格式的报告
下面的代码返回一个对象分析API&;PHP-获取不同格式的报告,php,google-analytics,google-analytics-api,Php,Google Analytics,Google Analytics Api,下面的代码返回一个对象Google\u Service\u analytics reporting\u getreports response $body = new Google_Service_AnalyticsReporting_GetReportsRequest(); $body->setReportRequests($aRequests); return $this->oAnalytics->reports->batchGet($body); 我想知道是否可以
Google\u Service\u analytics reporting\u getreports response
$body = new Google_Service_AnalyticsReporting_GetReportsRequest();
$body->setReportRequests($aRequests);
return $this->oAnalytics->reports->batchGet($body);
我想知道是否可以获得不同格式的报告,例如:
数组(维度、值)
是
googlereportingv4sdkforphp看起来像是从java代码中自动转换而来的,同时还有所有常见的对象过度使用
要转换为数组,假设您要求一维和一些度量:
$data = []
foreach ($this->oAnalytics->reports->batchGet($body)->getReports()[0]->getData()->getRows() as $row) {
$key = $row->dimensions[0]; // chose a unique value or dimension that works for your app, or remove and use $data[] = $value; below
$values = array_merge($row->metrics, $row->dimensions);
$data[$key] = $value;
}
这帮我完成了任务
$row给出如下内容
array(5 items)
0 => array(2 items)
0 => 'India' (5 chars)
1 => '1' (1 chars)
1 => array(2 items)
0 => 'Taiwan' (6 chars)
1 => '1' (1 chars)
2 => array(2 items)
0 => 'United States' (13 chars)
1 => '1' (1 chars)
3 => array(2 items)
0 => '(not set)' (9 chars)
1 => '4' (1 chars)
4 => array(2 items)
0 => 'United Kingdom' (14 chars)
1 => '82' (2 chars)
承认有点死神癖,这篇文章是谷歌搜索谷歌API PHP SDK疯狂类名的唯一结果。
array(5 items)
0 => array(2 items)
0 => 'India' (5 chars)
1 => '1' (1 chars)
1 => array(2 items)
0 => 'Taiwan' (6 chars)
1 => '1' (1 chars)
2 => array(2 items)
0 => 'United States' (13 chars)
1 => '1' (1 chars)
3 => array(2 items)
0 => '(not set)' (9 chars)
1 => '4' (1 chars)
4 => array(2 items)
0 => 'United Kingdom' (14 chars)
1 => '82' (2 chars)