Skip to content

Commit 6a395c6

Browse files
committed
document the finer practical points of usage
1 parent 63204a2 commit 6a395c6

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

fitbit/api.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,27 @@ def refresh_token(self):
162162

163163

164164
class Fitbit(object):
165+
"""
166+
Before using this class, create a Fitbit app
167+
`here <https://dev.fitbit.com/apps/new>`_. There you will get the client id
168+
and secret needed to instantiate this class. When first authorizing a user,
169+
make sure to pass the `redirect_uri` keyword arg so fitbit will know where
170+
to return to when the authorization is complete. See
171+
`gather_keys_oauth2.py <https://github.com/orcasgit/python-fitbit/blob/master/gather_keys_oauth2.py>`_
172+
for a reference implementation of the authorization process. You should
173+
save ``access_token``, ``refresh_token``, and ``expires_at`` from the
174+
returned token for each user you authorize.
175+
176+
When instantiating this class for use with an already authorized user, pass
177+
in the ``access_token``, ``refresh_token``, and ``expires_at`` keyword
178+
arguments. We also strongly recommend passing in a ``refresh_cb`` keyword
179+
argument, which should be a function taking one argument: a token dict.
180+
When that argument is present, we will automatically refresh the access
181+
token when needed and call this function so that you can save the updated
182+
token data. If you don't save the updated information, then you could end
183+
up with invalid access and refresh tokens, and the only way to recover from
184+
that is to reauthorize the user.
185+
"""
165186
US = 'en_US'
166187
METRIC = 'en_UK'
167188

@@ -187,7 +208,9 @@ class Fitbit(object):
187208
'frequent',
188209
]
189210

190-
def __init__(self, client_id, client_secret, system=US, **kwargs):
211+
def __init__(self, client_id, client_secret, access_token=None,
212+
refresh_token=None, expires_at=None, refresh_cb=None,
213+
redirect_uri=None, system=US, **kwargs):
191214
"""
192215
Fitbit(<id>, <secret>, access_token=<token>, refresh_token=<token>)
193216
"""

0 commit comments

Comments
 (0)