You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/ERROR_HANDLING.md
+86Lines changed: 86 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -163,6 +163,92 @@ except FitbitAPIException as e:
163
163
print(f"API error: {e.message}") # Catches all other API errors
164
164
```
165
165
166
+
### Handling OAuth-Specific Exceptions
167
+
168
+
OAuth errors require special handling. Here's how to handle different OAuth exception subtypes:
169
+
170
+
```python
171
+
from fitbit_client.exceptions import ExpiredTokenException, InvalidTokenException
172
+
from fitbit_client.exceptions import InvalidClientException, InvalidGrantException
173
+
174
+
try:
175
+
# Make an API call that requires authentication
176
+
client.get_profile()
177
+
except ExpiredTokenException as e:
178
+
# Token has expired but couldn't be auto-refreshed
179
+
print(f"Token expired: {e.message}")
180
+
# Attempt to re-authenticate
181
+
client.authenticate()
182
+
except InvalidTokenException as e:
183
+
# Token is invalid (e.g., revoked by user)
184
+
print(f"Token invalid: {e.message}")
185
+
# Re-authenticate from scratch
186
+
client.authenticate()
187
+
except InvalidClientException as e:
188
+
# Client credentials are incorrect
189
+
print(f"Client credentials error: {e.message}")
190
+
# Check client_id and client_secret
191
+
except InvalidGrantException as e:
192
+
# Refresh token is invalid
193
+
print(f"Invalid refresh token: {e.message}")
194
+
# Re-authenticate to get a new refresh token
195
+
client.authenticate()
196
+
```
197
+
198
+
## Token Refresh Strategies
199
+
200
+
The client automatically handles token refresh when tokens expire. However, you may want to implement custom token refresh strategies for your application.
201
+
202
+
### Automatic Token Refresh
203
+
204
+
By default, the client refreshes tokens automatically:
205
+
206
+
1. When initializing the client with cached tokens
207
+
2. During API calls when a token expires
208
+
3. When explicitly calling a method that requires authentication
Copy file name to clipboardExpand all lines: docs/NAMING.md
+82-8Lines changed: 82 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,14 +28,88 @@ easier to find based on the official documentation.
28
28
29
29
## Inconsistencies in the API
30
30
31
-
The Fitbit API contains several inconsistencies, which our method names
32
-
necessarily reflect:
33
-
34
-
-`create_activity_goals` creates only one goal at a time
35
-
-`add_favorite_foods` adds one food at a time, while all other creation methods
36
-
use "create" prefix
37
-
- Some pluralized methods return lists, while others return dictionaries
38
-
containing lists
31
+
The Fitbit API contains several inconsistencies, which our method names and implementation necessarily reflect. Understanding these inconsistencies can help you navigate the API more effectively:
32
+
33
+
### Method Name vs. Functionality Inconsistencies
34
+
35
+
-`create_activity_goals` creates only one goal at a time, despite the plural name
36
+
-`add_favorite_foods` adds one food at a time, while all other creation methods use "create" prefix
37
+
-`get_sleep_goals` returns a single goal, not multiple goals
38
+
- Some pluralized methods return lists, while others return dictionaries containing lists
39
+
40
+
### Parameter and Response Format Inconsistencies
41
+
42
+
```python
43
+
# Sleep endpoint uses a different API version than most other endpoints
44
+
client.sleep.get_sleep_log_by_date(date="2025-01-01") # Uses API v1.2
45
+
client.activity.get_daily_activity_summary(date="2025-01-01") # Uses API v1
46
+
47
+
# Sleep date parameters have inconsistent response behavior
48
+
# The request uses "2025-01-01" but response might contain data from "2025-01-02"
Our library handles these inconsistencies internally to provide a unified experience, but it's helpful to be aware of them when working with the raw API responses.
0 commit comments