Skip to content
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Cannot retrieve contributors at this time
// MUST be using composer
require_once '/home/csengineer13/';
$client = new Google_Client();
$client->setApplicationName("API Project"); // Name of proj in GoogleDeveloperConsole
// Generated in GoogleDeveloperConsole --> Credentials --> Service Accounts
$client->setAuthConfig('/home/csengineer13/secure-creds/API Project-c0a14bc34a03.json');
// Grab token if it's set
if (isset($_SESSION['service_token'])) {
// Refresh if expired
if ($client->isAccessTokenExpired()) {
// Pin to Session
$_SESSION['service_token'] = $client->getAccessToken();
$service = new Google_Service_Analytics($client);
// Adding Dimensions
$params = array('dimensions' => 'ga:userType');
// requesting the data
$data = $service->data_ga->get("ga:110849216", "2015-10-01", "2015-11-08", "ga:users,ga:sessions", $params );
<title>PHP Only: Data Query</title>
<h1>Results for: 2015-10 to 2015-11-08</h1>
<table border="1">
//Printing column headers
foreach($data->getColumnHeaders() as $header){
print "<td><b>".$header['name']."</b></td>";
//printing each row.
foreach ($data->getRows() as $row) {
print "<tr><td>".$row[0]."</td><td>".$row[1]."</td><td>".$row[2]."</td></tr>";
<td colspan="2">Rows Returned <?php print $data->getTotalResults();?> </td>