Netatmo Weather のAPIをとりあえず使ってみる
準備
- https://dev.netatmo.com/
- 上部メニューCREATE YOUR APP クリック
- App name, App Description を入力
- "I accept Netatmo APIs Terms and Conditions" にチェックを入れて同意する
Client id
とClient secret
が作成される
API使ってみる
- API を使用する前に認可する必要がある
- OAuth 2.0 を使用して認可する
- OAuth2.0 については、https://qiita.com/TakahikoKawasaki/items/200951e5b5929f840a1f が分かりやすい
- https://dev.netatmo.com/resources/technical/guides/authentication
今回はクライアントからの使用を想定しているので、Authentication for native client を参照
curl で試してみる
- access_token 取得
curl -w '\n' 'https://api.netatmo.com/oauth2/token' --data 'grant_type=password&client_id=xxx&client_secret=xxx&username=xxx&password=xxxx&scope=read_station' -X POST {"access_token":"xxxx","refresh_token":"xxx","scope":["read_station"],"expires_in":10800,"expire_in":10800}
curl https://api.netatmo.net/api/getstationsdata\?access_token\=xxx json のレスポンス
json のレスポンスが返ってきて、中のデータ(温度や湿度など)が正しいことを確認出来た。