跳转到主要内容

Withings API的库

项目描述

Python withings-api Build status Coverage Status PyPI

Python库,用于Withings Health API

Withings Health API https://developer.withings.com/oauth2/

使用OAuth 2.0进行身份验证。您需要在此创建应用程序以从Withings获取客户端ID和消费者密钥: http://developer.withings.com/oauth2/

安装

pip install withings-api

使用

完整示例,请查看scripts/integration_test.py中的集成测试。它包含如何使用API的示例。

from withings_api import WithingsAuth, WithingsApi, AuthScope
from withings_api.common import get_measure_value, MeasureType

auth = WithingsAuth(
    client_id='your client id',
    consumer_secret='your consumer secret',
    callback_uri='your callback uri',
    mode='demo',  # Used for testing. Remove this when getting real user data.
    scope=(
        AuthScope.USER_ACTIVITY,
        AuthScope.USER_METRICS,
        AuthScope.USER_INFO,
        AuthScope.USER_SLEEP_EVENTS,
    )
)

authorize_url = auth.get_authorize_url()
# Have the user goto authorize_url and authorize the app. They will be redirected back to your redirect_uri.

credentials = auth.get_credentials('code from the url args of redirect_uri')

# Now you are ready to make calls for data.
api = WithingsApi(credentials)

meas_result = api.measure_get_meas()
weight_or_none = get_measure_value(meas_result, with_measure_type=MeasureType.WEIGHT)

构建

构建、测试和代码审查都由一个脚本完成。您只需要少量依赖项。

依赖项

  • 您的路径中存在python3。
  • python3的venv模块。

构建脚本将设置venv、依赖项、测试、代码审查并将项目打包。

./scripts/build.sh

集成测试

存在一个简单的集成测试,该测试针对Withings的演示数据运行。最好在成功构建后运行此测试。

注意:在更改源代码后,您需要运行构建来使集成测试能够识别更改。

./scripts/build.sh
source ./venv/bin/activate
./scripts/integration_test.py --client-id <your client id> --consumer-secret <your consumer secret> --callback-uri <your clalback uri>

集成测试将在每次运行之间将凭据缓存在 <项目根目录>/.credentials 文件中。如果您收到一个说访问令牌已过期的错误,请删除该凭据文件并再次尝试。

项目详情


下载文件

下载您平台上的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源代码分发

withings_api-2.4.0.tar.gz (14.8 kB 查看哈希值)

上传时间 源代码

构建分发

withings_api-2.4.0-py3-none-any.whl (13.5 kB 查看哈希值)

上传时间 Python 3

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面