4848 client.authenticate()
4949
5050 # Make a request (e.g., get user profile)
51+ # You can access resources directly:
5152 profile = client.user.get_profile()
53+ # Or use method aliases for shorter syntax:
54+ profile = client.get_profile()
5255 print (dumps(profile, indent = 2 ))
5356
5457except Exception as e:
@@ -59,63 +62,109 @@ The response will always be the body of the API response, and is almost always a
5962` Dict ` , ` List ` or ` None ` . ` nutrition.get_activity_tcx ` is the exception. It
6063returns XML (as a ` str ` ).
6164
62- ## Authentication Methods
65+ ## Method Aliases
6366
64- ### 1. Automatic (Recommended)
65-
66- Uses a local callback server to automatically handle the OAuth2 flow:
67+ All resource methods are available directly from the client instance. This means
68+ you can use:
6769
6870``` python
69- client = FitbitClient(
70- client_id = " YOUR_CLIENT_ID" ,
71- client_secret = " YOUR_CLIENT_SECRET" ,
72- redirect_uri = " https://localhost:8080" ,
73- use_callback_server = True # default is True
74- )
71+ # Short form with method aliases
72+ client.get_profile()
73+ client.get_daily_activity_summary(date = " 2025-03-06" )
74+ client.get_sleep_log_by_date(date = " 2025-03-06" )
75+ ```
7576
76- # Will open browser and handle callback automatically
77- client.authenticate()
77+ Instead of the longer form:
78+
79+ ``` python
80+ # Standard resource access
81+ client.user.get_profile()
82+ client.activity.get_daily_activity_summary(date = " 2025-03-06" )
83+ client.sleep.get_sleep_log_by_date(date = " 2025-03-06" )
7884```
7985
80- ### 2. Manual URL Copy/Paste
86+ Both approaches are equivalent, but aliases provide a more concise syntax.
8187
82- If you prefer not to use a local server:
88+ ## Authentication
89+
90+ Uses a local callback server to automatically handle the OAuth2 flow:
8391
8492``` python
8593client = FitbitClient(
8694 client_id = " YOUR_CLIENT_ID" ,
8795 client_secret = " YOUR_CLIENT_SECRET" ,
8896 redirect_uri = " YOUR_REGISTERED_REDIRECT_URI" ,
89- token_cache_path = " /tmp/fb_tokens.json" ,
90- use_callback_server = True
97+ token_cache_path = " /tmp/fb_tokens.json" # Optional: saves tokens between sessions
98+ redirect_uri = " YOUR_REGISTERED_REDIRECT_URI" ,
99+ token_cache_path = " /tmp/fb_tokens.json" # Optional: saves tokens between sessions
91100)
92101
93- # Will open a browser and start a server to complete the flow (default), or
94- # prompt you on the command line to copy/paste the callback URL from the
95- # browser (see `use_callback_server`)
102+ # Will open browser and handle callback automatically
96103client.authenticate()
97104```
98105
106+ The ` token_cache_path ` parameter allows you to persist authentication tokens
107+ between sessions. If provided, the client will:
108+
109+ 1 . Load existing tokens from this file if available (avoiding re-authentication)
110+
111+ 2 . Save new or refreshed tokens to this file automatically
112+
113+ 3 . Handle token refresh when expired tokens are detected The ` token_cache_path `
114+ parameter allows you to persist authentication tokens between sessions. If
115+ provided, the client will:
116+
117+ 4 . Load existing tokens from this file if available (avoiding re-authentication)
118+
119+ 5 . Save new or refreshed tokens to this file automatically
120+
121+ 6 . Handle token refresh when expired tokens are detected
122+
99123## Setting Up Your Fitbit App
100124
1011251 . Go to dev.fitbit.com and create a new application
1021262 . Set OAuth 2.0 Application Type to "Personal"
103- 3 . Set Callback URL to:
104- - For automatic method: "https://localhost:8080 "
105- - For manual method: Your preferred redirect URI
106- 4 . Copy your Client ID and Client Secret
107-
108- Additional documentation:
109-
110- - To understand the logging implemementation, see [ LOGGING] ( docs/LOGGING.md )
111- - To understand validations and the exception hierarchy, see
112- [ VALIDATIONS_AND_EXCEPTIONS] ( docs/VALIDATIONS_AND_EXCEPTIONS.md )
113- - It's work checking out
114- [ Fitbit's Best Practices] ( https://dev.fitbit.com/build/reference/web-api/developer-guide/best-practices/ )
115- - For some general development guidelines, see
116- [ DEVELOPMENT] ( docs/DEVELOPMENT.md ) .
117- - For style guidelines (mostly enforced through varius linters and formatters)
118- see [ STYLE] ( docs/STYLE.md ) .
127+ 3 . Set Callback URL to "https://localhost:8080 " (or your preferred local URL)
128+ 4 . Set Callback URL to "https://localhost:8080 " (or your preferred local URL)
129+ 5 . Copy your Client ID and Client Secret
130+
131+ ## Additional Documentation
132+
133+ ### For API Library Users
134+
135+ - [ LOGGING.md] ( docs/LOGGING.md ) : Understanding the dual-logger system
136+ - [ TYPES.md] ( docs/TYPES.md ) : JSON type system and method return types
137+ - [ NAMING.md] ( docs/NAMING.md ) : API method naming conventions
138+ - [ VALIDATIONS.md] ( docs/VALIDATIONS.md ) : Input parameter validation
139+ - [ ERROR_HANDLING.md] ( docs/ERROR_HANDLING.md ) : Exception hierarchy and handling
140+
141+ It's also worth reviewing
142+ [ Fitbit's Best Practices] ( https://dev.fitbit.com/build/reference/web-api/developer-guide/best-practices/ )
143+ for API usage.
144+
145+ ### Project Best Practices
146+
147+ - [ DEVELOPMENT.md] ( docs/DEVELOPMENT.md ) : Development environment and guidelines
148+ - [ STYLE.md] ( docs/STYLE.md ) : Code style and formatting standards
149+
150+ ## Additional Documentation
151+
152+ ### For API Library Users
153+
154+ - [ LOGGING.md] ( docs/LOGGING.md ) : Understanding the dual-logger system
155+ - [ TYPES.md] ( docs/TYPES.md ) : JSON type system and method return types
156+ - [ NAMING.md] ( docs/NAMING.md ) : API method naming conventions
157+ - [ VALIDATIONS.md] ( docs/VALIDATIONS.md ) : Input parameter validation
158+ - [ ERROR_HANDLING.md] ( docs/ERROR_HANDLING.md ) : Exception hierarchy and handling
159+
160+ It's also worth reviewing
161+ [ Fitbit's Best Practices] ( https://dev.fitbit.com/build/reference/web-api/developer-guide/best-practices/ )
162+ for API usage.
163+
164+ ### Project Best Practices
165+
166+ - [ DEVELOPMENT.md] ( docs/DEVELOPMENT.md ) : Development environment and guidelines
167+ - [ STYLE.md] ( docs/STYLE.md ) : Code style and formatting standards
119168
120169## Important Note - Subscription Support
121170
@@ -124,9 +173,20 @@ This client does not currently support the
124173and
125174[ deletion] ( https://dev.fitbit.com/build/reference/web-api/subscription/delete-subscription/ )
126175of
127- [ webhook subscrptions] ( https://dev.fitbit.com/build/reference/web-api/developer-guide/using-subscriptions/ ) .
128- The methods are implemented in comments and _ should_ work, but I have not had a
129- chance to verify a user confirm this.
176+ [ webhook subscriptions] ( https://dev.fitbit.com/build/reference/web-api/developer-guide/using-subscriptions/ ) .
177+ The methods are implemented in comments and should work, but I have not had a
178+ chance to verify them since this requires a publicly accessible server to
179+ receive webhook notifications.
180+
181+ If you're using this library with subscriptions and would like to help test and
182+ implement this functionality, please open an issue or pull request!
183+ [ webhook subscriptions] ( https://dev.fitbit.com/build/reference/web-api/developer-guide/using-subscriptions/ ) .
184+ The methods are implemented in comments and should work, but I have not had a
185+ chance to verify them since this requires a publicly accessible server to
186+ receive webhook notifications.
187+
188+ If you're using this library with subscriptions and would like to help test and
189+ implement this functionality, please open an issue or pull request!
130190
131191## License
132192
0 commit comments