fitbitr
makes it easy to interface with Fitbit data in R.
You can install the CRAN version of fitbitr
with:
Or you can install the latest development version from Github:
There are a few steps you’ll need to do before you can start pulling your Fitbit data:
Make an app here.
Fill in the fields as you like (see image below for guidance).
You’ll be redirected to a page with your credentials. Make sure you keep the Client ID, Client Secret, and Redirect URL. You’ll need them to finish the setup process. You can always refer back to the apps page to find them again.
Generate a token:
library(fitbitr)
generate_token(
client_id = <YOUR-CLIENT-ID>,
client_secret = <YOUR-CLIENT-SECRET>
callback = <YOUR-REDIRECT-URL>
)
scopes = c('scopes', 'you', 'want', 'enabled')
argument. You can find information on the available scope options here.cache = TRUE
or cache = <some-file-path>
. See the docs on httr::oauth2.0_token()
for details.And that’s it! You now have your Fitbit API credentials set up. fitbitr
tracks them behind the scenes for you, so all that you need to do at the start of each R session is either generate_token()
or load_cached_token()
, and you’ll be off and running.