<?php

require_once 'vendor/autoload.php';
use ImmersiveLabs\CaraAPI\Service\APIServiceFactory;
$clientId = "YOUR_APP_ID";
$clientSecret = "YOUR_APP_SECRET";
$username = "******";
$password = "******";
$scopes = array('analytic');
$cameraKey = "YOUR_CAMERA_KEY";
$authAPIService = APIServiceFactory::getAuthAPIService();
$analyticsAPIService = APIServiceFactory::getAnalyticsAPIService();
$accessToken = $authAPIService->getAccessToken($clientId, $clientSecret, $username, $password, $scopes);
$rawData = $analyticsAPIService->getRaw($accessToken, $cameraKey);
$ages = array($unknown = 0, $child = 0, $youngAdult = 0, $adult = 0, $senior = 0);
foreach ($rawData as $data) {
    $ages[$data['age']]++;
}
?>

<html>
<head>
    <!--Load the AJAX API-->
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">

        // Load the Visualization API and the piechart package.
        google.load('visualization', '1.0', {'packages':['corechart']});

        // Set a callback to run when the Google Visualization API is loaded.
        google.setOnLoadCallback(drawChart);
 /**
  * @return \ImmersiveLabs\CaraAPI\Service\API\AuthAPIService
  */
 public function getAuthAPIService()
 {
     return APIServiceFactory::getAuthAPIService();
 }