Coder Social home page Coder Social logo

python-withings's Introduction

Python library for the Withings API

Withings Body metrics Services API http://oauth.withings.com/api/doc

Uses Oauth 1.0 to authentify. You need to obtain a consumer key and consumer secret from Withings by creating an application here: https://oauth.withings.com/partner/add

Installation:

pip install withings

Usage:

from withings import WithingsAuth, WithingsApi
from settings import CONSUMER_KEY, CONSUMER_SECRET

auth = WithingsAuth(CONSUMER_KEY, CONSUMER_SECRET)
authorize_url = auth.get_authorize_url()
print "Go to %s allow the app and copy your oauth_verifier" % authorize_url

oauth_verifier = raw_input('Please enter your oauth_verifier: ')
creds = auth.get_credentials(oauth_verifier)

client = WithingsApi(creds)
measures = client.get_measures(limit=1)
print "Your last measured weight: %skg" % measures[0].weight 

python-withings's People

Contributors

brad avatar maximebf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-withings's Issues

auth.get_credentials ERROR Missing access token parameter.

Documented usage is not working on the following line
creds = auth.get_credentials(authorization_response)
in

redirect_uri = 'https://fit.XXXX.com/pages/authorize/withings'
client_id = 'XXXX'
client_secret = 'XXXX'

from nokia import NokiaAuth, NokiaApi

auth = NokiaAuth(client_id, client_secret, callback_uri=redirect_uri)
authorize_url = auth.get_authorize_url()
print("Go to %s allow the app and copy the url you are redirected to." % authorize_url)
authorization_response = input('Please enter your full authorization response url: ')
creds = auth.get_credentials(authorization_response)

client = NokiaApi(creds)
measures = client.get_measures(limit=1)
print("Your last measured weight: %skg" % measures[0].weight)

creds = client.get_credentials()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.1\helpers\pydev\_pydev_bundle\pydev_umd.py", line 198, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.1\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/Ethan/PycharmProjects/fitness/pages/pandasTesting.py", line 18, in <module>
    creds = auth.get_credentials(authorization_response)
  File "C:\Users\Ethan\PycharmProjects\fitness\venv\lib\site-packages\nokia\__init__.py", line 86, in get_credentials
    client_secret=self.consumer_secret)
  File "C:\Users\Ethan\PycharmProjects\fitness\venv\lib\site-packages\requests_oauthlib\oauth2_session.py", line 244, in fetch_token
    self._client.parse_request_body_response(r.text, scope=self.scope)
  File "C:\Users\Ethan\PycharmProjects\fitness\venv\lib\site-packages\oauthlib\oauth2\rfc6749\clients\base.py", line 415, in parse_request_body_response
    self.token = parse_token_response(body, scope=scope)
  File "C:\Users\Ethan\PycharmProjects\fitness\venv\lib\site-packages\oauthlib\oauth2\rfc6749\parameters.py", line 425, in parse_token_response
    validate_token_parameters(params)
  File "C:\Users\Ethan\PycharmProjects\fitness\venv\lib\site-packages\oauthlib\oauth2\rfc6749\parameters.py", line 435, in validate_token_parameters
    raise MissingTokenError(description="Missing access token parameter.")
oauthlib.oauth2.rfc6749.errors.MissingTokenError: (missing_token) Missing access token parameter.

Unable to decode token

Thanks for creating this. I am using this on Python 3.4 with the following modified example code:

from withings import WithingsAuth, WithingsApi
from ApiKeys import CONSUMER_KEY, CONSUMER_SECRET

auth = WithingsAuth(CONSUMER_KEY, CONSUMER_SECRET)
authorize_url = auth.get_authorize_url()
print("Go to %s allow the app and copy your oauth_verifier" % authorize_url)

oauth_verifier = input('Please enter your oauth_verifier: ')
print(oauth_verifier)
creds = auth.get_credentials(oauth_verifier)

client = WithingsApi(creds)
measures = client.get_measures(limit=1)
print("Your last measured weight: %skg" % measures[0].weight)

I get the authorization url and can follow the prompts to get to a page which has

Access granted
oauth_token=831261652e38dc071cc0f98997f7f6ebce766f3de43bb5c198e87c3f&oauth_verifier=jo9Ic2OpohhWxU  

When I enter this token at the prompt I get the following error. Any ideas what is going wrong?

Traceback (most recent call last):
  File "/Users/jweob/Library/Python/3.4/lib/python/site-packages/requests_oauthlib/oauth1_session.py", line 348, in _fetch_token
    token = dict(urldecode(r.text))
  File "/Users/jweob/Library/Python/3.4/lib/python/site-packages/requests_oauthlib/oauth1_session.py", line 33, in urldecode
    return json.loads(body)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/json/__init__.py", line 318, in loads
    return _default_decoder.decode(s)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/json/decoder.py", line 343, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/json/decoder.py", line 361, in raw_decode
    raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/jweob/PyCharmProjects/FatPi/Withings.py", line 11, in 
    creds = auth.get_credentials(oauth_verifier)
  File "/Users/jweob/Library/Python/3.4/lib/python/site-packages/withings/__init__.py", line 78, in get_credentials
    tokens = oauth.fetch_access_token('%s/access_token' % self.URL)
  File "/Users/jweob/Library/Python/3.4/lib/python/site-packages/requests_oauthlib/oauth1_session.py", line 297, in fetch_access_token
    token = self._fetch_token(url)
  File "/Users/jweob/Library/Python/3.4/lib/python/site-packages/requests_oauthlib/oauth1_session.py", line 354, in _fetch_token
    raise ValueError(error)
ValueError: Unable to decode token from token response. This is commonly caused by an unsuccessful request where a non urlencoded error message is returned. The decoding error was Expecting value: line 1 column 1 (char 0)

Process finished with exit code 1

Support Python 3.4

The PyPI install fails with simple stuff like the print statement and exception handling

OAuth 2.0 support

Nokia is sunsetting OAuth 1.0 support on November 30th, someone can update this library to OAuth 2.0?

Is this project still alive?

Without going through the process of downloading/installing, etc - is this project still working / alive? Any issues if I fork?

Authorise once and run script as a cron job. Is it possible?

Each time I run this script requires copy/pasting the url and authorizing the application, is it possible to only have to authorize the script once and get a long lived token and then rerun the script to return measurements from withings without having to manually authorize every time? I would like to run this script as a scheduled cron job and pump the values into my own database.
Any help would be much appreciated.

SPO2 measurement

you haven't add the spo2 measurement in the measure_types

class WithingsMeasureGroup(object):
MEASURE_TYPES = (('weight', 1), ('height', 4), ('fat_free_mass', 5),
('fat_ratio', 6), ('fat_mass_weight', 8),
('diastolic_blood_pressure', 9), ('systolic_blood_pressure', 10),
('heart_pulse', 11),('spo2',54))

more api measure type

can you update class WithingsMeasureGroup(object)
with ('muscle_mass', 76), ('hydration', 77), ('bone_mass', 88),('pulse_wave_velocity', 91) ?

class WithingsMeasureGroup(object):
    MEASURE_TYPES = (('weight', 1), ('height', 4), ('fat_free_mass', 5),
                     ('fat_ratio', 6), ('fat_mass_weight', 8),
                     ('diastolic_blood_pressure', 9), ('systolic_blood_pressure', 10),
                     ('heart_pulse', 11), ('muscle_mass', 76), ('hydration', 77),
                     ('bone_mass', 88),('pulse_wave_velocity', 91))

What Is The Official Withings Python Module To Use That Is Supported?

What Is The Official Withings Python Module To Use That Is Supported?

I was hoping somebody could help me understand this better. I am looking to interface with the Withings API, for the Withings bathroom scales. I have been using the Python module called “Nokia”, but it has not been updated in some time. Is there an “official” Withings Python module that should be used instead?

Here are 3 Withings modules I have found. Is there an “official” or preferred one to code with?

Thanks for any help!
Jean-Marie Vaneskahian
[email protected]
(January 31st, 2021)

Need callback_uri support

How can I add callback_uri support with OAuth1Session?

oauth = OAuth1Session(
    auth.consumer_key,
    client_secret=auth.consumer_secret,
    callback_uri=callback_url)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.