Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过php客户端使用google analytics api获取web统计信息_Php_Google App Engine_Web_Google Analytics Api_Google Api Php Client - Fatal编程技术网

如何通过php客户端使用google analytics api获取web统计信息

如何通过php客户端使用google analytics api获取web统计信息,php,google-app-engine,web,google-analytics-api,google-api-php-client,Php,Google App Engine,Web,Google Analytics Api,Google Api Php Client,如何使用PHP通过Google分析API检索Google分析数据 是否可以通过API获取页面状态 我正在与一个网站有30000页,我需要创建一个仪表板显示相应用户的页面统计信息 是的,通过使用PHP,可以获得您正在谈论的统计数据 有一个php客户端库,我建议您可以在上面找到它 因为您只能访问自己的数据,所以我建议您使用身份验证 简单的例子: <?php session_start(); require_once 'Google/Client.php'; require_once 'Goog

如何使用
PHP
通过
Google分析API
检索
Google分析
数据

是否可以通过API获取页面状态


我正在与一个网站有30000页,我需要创建一个仪表板显示相应用户的页面统计信息

是的,通过使用PHP,可以获得您正在谈论的统计数据

有一个php客户端库,我建议您可以在上面找到它

因为您只能访问自己的数据,所以我建议您使用身份验证

简单的例子:

<?php
session_start();
require_once 'Google/Client.php';
require_once 'Google/Service/Analytics.php';

/************************************************
  The following 3 values an befound in the setting
  for the application you created on  Google 
  Developers console.
  The Key file should be placed in a location
  that is not accessable from the web. outside of 
  web root.

  In order to access your GA account you must
  Add the Email address as a user at the 
  ACCOUNT Level in the GA admin. 
 ************************************************/
$client_id = '1046123799103-nk421gjc2v8mlr2qnmmqaak04ntb1dbp.apps.googleusercontent.com';
$Email_address = '1046123799103-nk421gjc2v8mlr2qnmmqaak04ntb1dbp@developer.gserviceaccount.com';
$key_file_location = '629751513db09cd21a941399389f33e5abd633c9-privatekey.p12';

$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);  
$accounts = $service->management_accountSummaries->listManagementAccountSummaries();

//calulating start date
$date = new DateTime(date("Y-m-d"));
$date->sub(new DateInterval('P10D'));

//Adding Dimensions
$params = array('dimensions' => 'ga:userType');
// requesting the data
$data = $service->data_ga->get("ga:78110423", $date->format('Y-m-d'),  date("Y-m-d"), "ga:users,ga:sessions", $params );


?><html>
<?php echo $date->format('Y-m-d') . " - ".date("Y-m-d"). "\n";?>
<table>
<tr>
<?php
//Printing column headers
foreach($data->getColumnHeaders() as $header){  
    print "<td>".$header['name']."</td>";   
}
?>
</tr>
<?php
//printing each row.
foreach ($data->getRows() as $row) {    
    print "<tr><td>".$row[0]."</td><td>".$row[1]."</td><td>".$row[2]."</td></tr>";  
}

//printing the total number of rows
?>
<tr><td colspan="2">Rows Returned <?php print $data->getTotalResults();?> </td></tr>
</table>
</html>
<?php

?>

返回的行数
我想你可以在网站上找到这段代码的教程