Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need Help With Use Of Library - How To Refresh Key #30

Open
jeangv opened this issue Nov 26, 2018 · 2 comments
Open

Need Help With Use Of Library - How To Refresh Key #30

jeangv opened this issue Nov 26, 2018 · 2 comments

Comments

@jeangv
Copy link

jeangv commented Nov 26, 2018

All I want to do is pull my own weight data from the Withings API. I finally figured out how to generate a "nokia.cfg" file based on the docs for the library. It is populated with:

access_token
token_expiry
token_type
refresh_token
user_id
client_id
consumer_secret

To use the API I hard coded these values into "NokiaCredentials" and it worked PERFECT for a few hours. Then I got an error "oauthlib.oauth2.rfc6749.errors.TokenExpiredError: (token_expired)"

I know from the Withings API docs I am supposed to somehow update the both the Access Token and the Refresh Token, but I have no idea how to do that. I read in the Python Withings code to use "refresh_cb". If that is how I get the updated tokens, can someone please post a simple example how to get the updated tokens?

I love that this Python Library exists because the Withings API is quite difficult to authenticate against just to pull my own weight data.

Thanks for ANY and all help! I will gladly donate to anyone that will help me... Thanks again!

@jeangv
Copy link
Author

jeangv commented Nov 27, 2018

Ok I still do not know how to get a new refresh token and new access token using this library, but I have figured out how to get them OUTSIDE of the the library.

import requests
import json
withings_url = "https://account.withings.com/oauth2/token"
post_data = {"grant_type": "refresh_token", "client_id": "{Your API Client ID}", "client_secret": "{Your API Client Secret}", "refresh_token": "{The Current Valid Refresh Token}"}
response = requests.post(url=withings_url, data=post_data)
json_data = json.loads(response.text)
print("New Access Token:  " + json_data['access_token'])
print("New Refresh Token: " + json_data['refresh_token'])

I am sure I can do the same thing with this library in a more elegant way if someone would explain it to me and others.

@brad
Copy link
Member

brad commented Nov 28, 2018

Sorry about that @jeangv I am working on this in #31

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants