diff --git a/src/withings_api_example/www.py b/src/withings_api_example/www.py index 383bb80..8763b70 100644 --- a/src/withings_api_example/www.py +++ b/src/withings_api_example/www.py @@ -44,25 +44,26 @@ def get_token(): code = request.args.get('code') state = request.args.get('state') - payload = {'grant_type': 'authorization_code', + payload = {'action': 'requesttoken', + 'grant_type': 'authorization_code', 'client_id': CLIENT_ID, 'client_secret': CUSTOMER_SECRET, 'code': code, 'redirect_uri': CALLBACK_URI } - r_token = requests.post(f'{ACCOUNT_URL}/oauth2/token', + r_token = requests.post(f'{WBSAPI_URL}/v2/oauth2', data=payload).json() - access_token = r_token.get('access_token', '') + access_token = r_token.get('body', {}).get('access_token') # GET Some info with this token headers = {'Authorization': 'Bearer ' + access_token} - payload = {'action': 'getdevice'} + data = {'action': 'getdevice'} # List devices of returned user - r_getdevice = requests.get(f'{WBSAPI_URL}/v2/user', + r_getdevice = requests.post(f'{WBSAPI_URL}/v2/user', headers=headers, - params=payload).json() + data=data).json() - return r_getdevice + return r_getdevice \ No newline at end of file