1
获取数据我有一个服务帐户e.g 浏览量,用户,跳出率等从谷歌Analytics(分析)中获取数据。我已经在我的开发人员电子邮件地址上设置了权限,以访问我的属性数据。谷歌分析报告API V3使用PHP
出7,我能够从5个属性/网站,但其他2 获取数据不工作
虽然这两个账户对谷歌Analytics系统管理>用户管理访问权限。我正在使用PHP的Google Analytics V3
。以下是我部分使用的代码。
$account_id = 'ga:343434334'; // my view id goes here
$client = new Google_Client();
$client->setApplicationName("Client_Library_Examples");
$key = file_get_contents($key_file_location);
// seproate additional scopes with a comma
$scopes ="https://www.googleapis.com/auth/analytics.readonly";
$cred = new Google_Auth_AssertionCredentials(
$Email_address,
array($scopes),
$key
);
$client->setAssertionCredentials($cred);
if($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
$service = new Google_Service_Analytics($client);
// get page threshold
$optParams1 = array(
'dimensions' => 'ga:pageDepth',
'sort' => '-ga:users',
'filters' => 'ga:[email protected]',
'max-results' => '1'
);
$results1 = $service->data_ga->get($account_id, $start_date, $end_date, 'ga:users', $optParams1);
print '<pre>';
print_r(results1);
printt '</pre>';
感谢您的回答,我在帐户级别获得了我的许可。我实际上遇到了这个问题,我认为我无法从GA获取数据,但原因是“我过滤了实际上为什么空白的指标”。谢谢 :) –