This is a complete python implementation of the Fitbit API.
It uses oAuath for authentication, it supports both us and si measurements
Here is some example usage:
import fitbit
unauth_client = fitbit.Fitbit('<consumer_key>', '<consumer_secret>')
# certain methods do not require user keys
unauth_client.activities()
# You'll have to gather the user keys on your own, or try ./fitbit/gather_keys_cli.py <con_key> <con_sec> for development
authd_client = fitbit.Fitbit('<consumer_key>', '<consumer_secret>', user_key='<user_key>', user_secret='<user_secret>')
authd_client.sleep()
Some assumptions you should note. Anywhere it says user_id=None, it assumes the current user_id from the credentials given, and passes a - through the API. Anywhere it says date=None, it should accept either None or a date or datetime object (anything with proper strftime will do), or a string formatted as %Y-%m-%d.
Retrieving and logging of each type of collection data.
This implements the following methods:
body(date=None, user_id=None, data=None)
activities(date=None, user_id=None, data=None)
foods(date=None, user_id=None, data=None)
water(date=None, user_id=None, data=None)
sleep(date=None, user_id=None, data=None)
heart(date=None, user_id=None, data=None)
bp(date=None, user_id=None, data=None)
deleting each type of collection data
This builds the following methods:
delete_body(log_id)
delete_activities(log_id)
delete_foods(log_id)
delete_water(log_id)
delete_sleep(log_id)
delete_heart(log_id)
delete_bp(log_id)
This builds the convenience methods on initialization:
recent_foods(user_id=None, qualifier='')
favorite_foods(user_id=None, qualifier='')
frequent_foods(user_id=None, qualifier='')
Convenience method for respond_to_invite
This implements the following methods:
recent_activities(user_id=None, qualifier='')
favorite_activities(user_id=None, qualifier='')
frequent_activities(user_id=None, qualifier='')
https://wiki.fitbit.com/display/API/API-Add-Favorite-Activity
https://wiki.fitbit.com/display/API/API-Delete-Favorite-Activity
https://wiki.fitbit.com/display/API/API-Delete-Favorite-Food
https://wiki.fitbit.com/display/API/API-Get-Friends-Leaderboard
Convenience Method for https://wiki.fitbit.com/display/API/API-Create-Invite
Convenience Method for https://wiki.fitbit.com/display/API/API-Create-Invite
https://wiki.fitbit.com/display/API/Fitbit+Subscriptions+API
Convenience method for respond_to_invite
https://wiki.fitbit.com/display/API/Fitbit+Subscriptions+API
The time series is a LOT of methods, (documented at url below) so they don’t get their own method. They all follow the same patterns, and return similar formats.
Taking liberty, this assumes a base_date of today, the current user, and a 1d period.
Get a user profile. You can get other user’s profile information by passing user_id, or you can get the current user’s by not passing a user_id
Set a user profile. You can set your user profile information by passing a dictionary of attributes that will be updated.