@@ -94,58 +94,67 @@ client = FitbitClient(
9494 client_id = " YOUR_CLIENT_ID" ,
9595 client_secret = " YOUR_CLIENT_SECRET" ,
9696 redirect_uri = " YOUR_REGISTERED_REDIRECT_URI" ,
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
97+ token_cache_path = " /tmp/fb_tokens.json"
10098)
10199
102100# Will open browser and handle callback automatically
103101client.authenticate()
104102```
105103
106- The ` token_cache_path ` parameter allows you to persist authentication tokens
107- between sessions. If provided, the client will :
104+ You can also load your credentials from a JSON file, which is useful for keeping
105+ secrets out of your code :
108106
109- 1 . Load existing tokens from this file if available (avoiding re-authentication)
107+ ``` python
108+ from json import load
109+ from fitbit_client import FitbitClient
110110
111- 2 . Save new or refreshed tokens to this file automatically
111+ # Load credentials from a JSON file
112+ with open (" secrets.json" ) as f:
113+ secrets = load(f)
112114
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:
115+ # Initialize Fitbit OAuth2 flow and get a client
116+ client = FitbitClient(** secrets)
116117
117- 4 . Load existing tokens from this file if available (avoiding re-authentication)
118+ # Authenticate as usual
119+ client.authenticate()
120+ ```
118121
119- 5 . Save new or refreshed tokens to this file automatically
122+ Where secrets.json contains:
120123
121- 6 . Handle token refresh when expired tokens are detected
124+ ``` json
125+ {
126+ "client_id" : " YOUR_CLIENT_ID" ,
127+ "client_secret" : " YOUR_CLIENT_SECRET" ,
128+ "redirect_uri" : " https://localhost:8080"
129+ }
130+ ```
122131
123- ## Setting Up Your Fitbit App
132+ You can also include the optional token_cache_path:
124133
125- 1 . Go to dev.fitbit.com and create a new application
126- 2 . Set OAuth 2.0 Application Type to "Personal"
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
134+ ``` json
135+ {
136+ "client_id" : " YOUR_CLIENT_ID" ,
137+ "client_secret" : " YOUR_CLIENT_SECRET" ,
138+ "redirect_uri" : " https://localhost:8080" ,
139+ "token_cache_path" : " /tmp/tokens.json"
140+ }
141+ ```
130142
131- ## Additional Documentation
143+ The ` token_cache_path ` parameter allows you to persist authentication tokens
144+ between sessions. If provided, the client will:
132145
133- ### For API Library Users
146+ 1 . Load existing tokens from this file if available (avoiding re-authentication)
134147
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
148+ 2 . Save new or refreshed tokens to this file automatically
140149
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.
150+ 3 . Handle token refresh when expired tokens are detected
144151
145- ### Project Best Practices
152+ ## Setting Up Your Fitbit App
146153
147- - [ DEVELOPMENT.md] ( docs/DEVELOPMENT.md ) : Development environment and guidelines
148- - [ STYLE.md] ( docs/STYLE.md ) : Code style and formatting standards
154+ 1 . Go to dev.fitbit.com and create a new application
155+ 2 . Set OAuth 2.0 Application Type to "Personal"
156+ 3 . Set Callback URL to "https://localhost:8080 " (or your preferred local URL)
157+ 4 . Copy your Client ID and Client Secret
149158
150159## Additional Documentation
151160
@@ -178,13 +187,6 @@ The methods are implemented in comments and should work, but I have not had a
178187chance to verify them since this requires a publicly accessible server to
179188receive webhook notifications.
180189
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-
188190If you're using this library with subscriptions and would like to help test and
189191implement this functionality, please open an issue or pull request!
190192
0 commit comments