require_once 'NAApiClient.php';
require_once 'Config.php';
$client = new NAApiClient(array("client_id" => $client_id, "client_secret" => $client_secret, "scope" => NAScopes::SCOPE_READ_STATION));
//Test if code is provided in get parameters (that means user has already accepted the app and has been redirected here)
if (isset($_GET["code"])) {
    try {
        // Get the token for later usage.(you can store $tokens["refresh_token"] for retrieving a new access_token next time)
        $tokens = $client->getAccessToken();
    } catch (NAClientException $ex) {
        echo "An error happend while trying to retrieve your tokens\n";
        echo "Reason : " . $ex->getMessage() . "\n";
        die;
    }
    try {
        $helper = new NAApiHelper($client);
        $user = $helper->api("getuser", "POST");
        $devicelist = $helper->simplifyDeviceList();
        $mesures = $helper->getLastMeasures($client, $devicelist);
        ?>
        <html><body><pre><code>
<?php 
        echo json_format(json_encode($mesures));
        ?>
        </code></pre></body></html>
<?php 
    } catch (NAClientException $ex) {
        echo "An error happend while trying to retrieve your last measures\n";
        echo $ex->getMessage() . "\n";
    }
} else {
    if (isset($_GET["error"])) {