Advertisement
Guest User

PHP

a guest
Sep 29th, 2015
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. <?php
  2.  
  3. $password="YOUR_NETATMO_API_PASSWORD";
  4. $username="YOUR_NETATMO_API_EMAIL";
  5.  
  6. $app_id = "APP_ID_FROM_API";
  7. $app_secret = "APP_SECRET_FROM_API";
  8.  
  9. $token_url = "https://api.netatmo.net/oauth2/token";
  10. $postdata = http_build_query(
  11. array(
  12. 'grant_type' => "password",
  13. 'client_id' => $app_id,
  14. 'client_secret' => $app_secret,
  15. 'username' => $username,
  16. 'password' => $password,
  17. 'scope' => "read_camera"
  18. )
  19. );
  20.  
  21. $opts = array('http' =>
  22. array(
  23. 'method' => 'POST',
  24. 'header' => 'Content-type: application/x-www-form-urlencoded',
  25. 'content' => $postdata
  26. )
  27. );
  28.  
  29. $context = stream_context_create($opts);
  30. $response = file_get_contents($token_url, false, $context);
  31.  
  32. $params = null;
  33. $params = json_decode($response, true);
  34. $api_url = "https://api.netatmo.net/api/getuser?access_token=" . $params['access_token'];
  35. $requete = file_get_contents($api_url);
  36.  
  37. $url_welcome = "https://api.netatmo.net/api/gethomedata?access_token=" . $params['access_token'] . "&size=1";
  38.  
  39. $welcome = file_get_contents($url_welcome);
  40.  
  41. echo $welcome;
  42.  
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement