fitbitr makes it easy to interface with Fitbit data in R.
You can install the CRAN version of fitbitr with:
install.packages("fitbitr")
Or you can install the latest development version from Github:
# install.packages("devtools")
devtools::install_github("mrkaye97/fitbitr")
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:
``` r library(fitbitr)
.fitbitr_token <- generate_oauth_token( oauth_app_name = , client_id = , client_secret = callback = ) ```
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 generate_token(). On
a session restart, generate_token() will try to laod a token from
your .httr-oauth if it exists.
fitbitrOnce you have a token, using fitbitr is very straightforward:
```r
> get_steps("2020-05-21", "2020-05-28")
# A tibble: 8 × 2
date steps
<date> <dbl>
1 2020-05-21 3734
2 2020-05-22 5107
3 2020-05-23 5640
4 2020-05-24 6595
5 2020-05-25 8466
6 2020-05-26 5833
7 2020-05-27 8616
8 2020-05-28 3161
```
fitbitr tries to return a useful, tidy object back to you from the
API.
Given the structure of the Fitbit API, it doesn’t appear to be currently
possible to use fitbitr outside of an interactive session. And
furthermore, it doesn’t help that Fitbit refresh tokens only last 8
hours, at which point you’d need another interactive session to generate
a new one.
For these reasons, it is not advised to try to use fitbitr
non-interactively, such as in a Shiny app server, a CI/CD process, a
background job, etc.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.