$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"])) {
        if ($_GET["error"] == "access_denied") {
            echo "You refused to let application access your netatmo data\n";
$helper = new NAApiHelper($client);
try {
    $tokens = $client->getAccessToken();
} catch (NAClientException $ex) {
    echo "An error happend while trying to retrieve your tokens\n";
    exit(-1);
}
// Retrieve User Info :
$user = $helper->api("getuser", "POST");
echo "-------------\n";
echo "- User Info -\n";
echo "-------------\n";
//print_r($user);
echo "OK\n";
echo "---------------\n";
echo "- Device List -\n";
echo "---------------\n";
$devicelist = $helper->simplifyDeviceList();
echo "OK\n";
echo "-----------------\n";
echo "- Last Measures -\n";
echo "-----------------\n";
$mesures = $helper->getLastMeasures();
print_r($mesures);
echo "OK\n";
echo "---------------------\n";
echo "- Last Day Measures -\n";
echo "---------------------\n";
$mesures = $helper->getAllMeasures(mktime() - 86400);
print_r($mesures);
echo "OK\n";