From 2ef9dba96359d1aff1581b0f5f58aa469fc0f693 Mon Sep 17 00:00:00 2001 From: Stefan Kral Date: Thu, 17 Aug 2023 12:03:07 +0200 Subject: [PATCH] quick fix netatmo API auth change --- examples/config.inc.php | 8 ++++++-- src/weather-data-netatmo.php | 27 +++++++++++++++++---------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/examples/config.inc.php b/examples/config.inc.php index 7e2271a..2b0ed42 100755 --- a/examples/config.inc.php +++ b/examples/config.inc.php @@ -17,8 +17,12 @@ // -- https://dev.netatmo.com/ $netatmo_client_id = 'client id'; $netatmo_client_secret = 'client secret'; -$netatmo_username = 'your email'; -$netatmo_password = 'your password'; +$netatmo_username = 'your email'; // depricated +$netatmo_password = 'your password'; // deprecated +// Generate tokens first with you app: https://dev.netatmo.com/apps/ +$netatmo_access_token = 'access|token'; +$netatmo_refresh_token = 'refresh|token'; + // Netatmo-API-PHP is used. // -- https://github.com/Netatmo/Netatmo-API-PHP $netatmo_nawsapiclient = '../netatmo/Clients/NAWSApiClient.php'; // Path to NAWSApiClient.php diff --git a/src/weather-data-netatmo.php b/src/weather-data-netatmo.php index d66815d..e577209 100755 --- a/src/weather-data-netatmo.php +++ b/src/weather-data-netatmo.php @@ -8,16 +8,23 @@ $config['scope'] = 'read_station'; $client = new NAWSApiClient($config); -$client->setVariable('username',$netatmo_username); -$client->setVariable('password',$netatmo_password); -try { - $tokens = $client->getAccessToken(); - $refresh_token = $tokens['refresh_token']; - $access_token = $tokens['access_token']; -} -catch(NAClientException $ex) { - echo 'Netatmo Wetterstation Daten: Es ist ein Fehler bei der Authorisation aufgetreten.'; -} + +# --- Auth #1 - not working anymore +#$client->setVariable('username',$netatmo_username); +#$client->setVariable('password',$netatmo_password); +#try { +# $tokens = $client->getAccessToken(); +# $refresh_token = $tokens['refresh_token']; +# $access_token = $tokens['access_token']; +#} +#catch(Netatmo\Exceptions\NAClientException $ex) { +# echo 'Netatmo Wetterstation Daten: Es ist ein Fehler bei der Authorisation aufgetreten.'; +#} + +# --- Auth #2 - working for now +$tokens = array("access_token" => $netatmo_access_token, + "refresh_token" => $netatmo_refresh_token); +$client->setTokensFromStore($tokens); $netatmo_outdoor_module = false; $netatmo_rain_module = false;