0

I am trying to get custom Google analytics results on my website. My authorization is completely functional. However when I test my script I receive the following error:

Fatal error: Uncaught exception 'Google_ServiceException' with message 'Error calling GET 5ddIg-G7w3W92o1Pcc">https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A12428978a12428978w47700129p48054548&start-date=2013-11-05&end-date=2013-11-07&metrics=ga%3Avisits%2Cga%3Apageviews%2Cga%3Abounces%2Cga%3AentranceBounceRate%2Cga%3AvisitBounceRate%2Cga%3AavgTimeOnSite&dimensions=ga%3Adate%2Cga%3Ayear%2Cga%3Amonth%2Cga%3Aday&key=AIzaSyDAo0pJuOoC0Ec_5ddIg-G7w3W92o1Pcc: (400) Invalid value 'ga:12428978a12428978w47700129p48054548'. Values must match the following regular expression: 'ga:[0-9]+'' in public_html/GoogleClientApi/src/io/Google_REST.php:66 Stack trace: #0 public_html/GoogleClientApi/src/io/Google_REST.php(36): Google_REST::decodeHttpResponse(Object(Google_HttpRequest)) #1 /public_html/GoogleClientApi/src/service/Google_ServiceResource.php(186): Google_REST::execute(Object(Google_HttpRequest)) #2 /home/apu in public_html/GoogleClientApi/src/io/Google_REST.php on line 66

The code that I am using is the following:

$projectId = 'XXX';

// metrics
$_params[] = 'date';
$_params[] = 'date_year';
$_params[] = 'date_month';
$_params[] = 'date_day';
// dimensions
$_params[] = 'visits';
$_params[] = 'pageviews';
$_params[] = 'bounces';
$_params[] = 'entrance_bounce_rate';
$_params[] = 'visit_bounce_rate';
$_params[] = 'avg_time_on_site';

$from = date('Y-m-d', time()-2*24*60*60); // 2 days
$to = date('Y-m-d'); // today
$metrics = 'ga:visits,ga:pageviews,ga:bounces,ga:entranceBounceRate,ga:visitBounceRate,ga:avgTimeOnSite';
$dimensions = 'ga:date,ga:year,ga:month,ga:day';
$data = $service->data_ga->get('ga:XXXXXXXX'.$projectId, $from, $to, $metrics, array('dimensions' => $dimensions));

foreach($data['rows'] as $row) {
   $dataRow = array();
   foreach($_params as $colNr => $column) echo $column . ': '.$row[$colNr].', ';
}

What am I missing?

4

2 回答 2

0

看来您的项目 ID 无效...

<br /><br />

说应该匹配ga:[0-9]+<br />

当前值ga:12428978a12428978w47700129p48054548
项目ID:a12428978w47700129p48054548

于 2013-11-07T19:32:08.367 回答
0

你目前正在通过这个

'ga:12428978a12428978w47700129p48054548'p这是不正确的,您只需要从

所以通过这个'ga:48054548'

于 2013-11-07T19:32:27.973 回答