Sign inSign up

tsubus/fitbit-steps

By tsubus

•Updated almost 6 years ago

Image
0

50K+

tsubus/fitbit-steps repository overview

⁠Initialize

There are a few manual steps necessary to be run the first time, in order obtain tokens that will work forever.

These steps have been taken from: https://www.forkingbytes.com/blog/using-the-fitbit-api-from-a-command-line-application-in-go/⁠

⁠Registering your app

  1. Navigate to Register an App.
  2. OAuth 2.0 Application Type: Client
  3. Callback URL: http://localhost⁠
  4. Default Access Type: Read & Write
  5. All other fields can be filled at user-discretion
  6. Once you hit the register button, your app will be created and you should be ready to use it.

⁠Obtaining an access code

  1. Navigate to Manage my Apps
  2. Click on your app name.
  3. Write down the OAuth 2.0 Client ID and Client Secret. You will need these later as input to the app.
  4. Click the link OAuth 2.0 tutorial page. When clicking the link, you will be redirected to a new page where you can test your OAuth 2.0 authorization. We will use this page to obtain a valid code to then get the access and refresh tokens.

In this page:

  1. Select Flow Type to be Authorization Code Flow
  2. Select the scopes that you will need (all is fine).
  3. Check the section just below the "Expires In(ms) section" that says: We’ve generated the authorization URL for you, all you need to do is just click on link below:
  4. That’s the link we want; the link that will give us the authorization code we need. Open that link and it will take you to Fitbit’s authorization page. There you just need to login with your Fitbit username and password, select the scopes you want and click the button to grant access.

Once you do that, you will be redirected to the URL you typed in the Callback URL when registering your app. If you used http://localhost⁠, you should see an error page now but that’s OK; we just need what’s on the URL, which should look like this:

https://localhost/?code=4c8bda4345baa41e39053aaef020996d2e1a19ce#_=⁠_

We will need this bit:

code=4c8bda4345baa41e39053aaef020996d2e1a19ce

This code will be used the first time we run the app. Make sure you run it briefly after obtaining it or it will expire, and a new one will have to be obtained.

⁠Running the app

⁠docker: see create-docker-fitbit-steps.sh

docker create \
  --name=fitbit-steps \
  -e PUID=USERID \
  -e PGID=GROUPID \
  -e TZ=Europe/Zurich \
  -e UMASK_SET=077 \
  -e CLIENT_ID=CLIENTID \
  -e CLIENT_SECRET=CLIENTSECRET \
  -e ONETIME_CODE=CODE \
  -v /home/user/config:/config \
  --restart always `#or: unless-stopped` \
  tsubus/fitbit-steps

USERID: your linux user ID GROUPID: your linux group ID CLIENTID: client ID of FitBit app CLIENTSECRET: client secret of FitBit app CODE: one time code obtained from steps above /home/user/config: path where fitbit-steps will store its configuration files

To start it:

docker start fitbit-steps

⁠Configuration

The YAML configuration file is located at /home/user/config/config.yaml (path as set above). It will be automatically generated during first run. Adjust it accordingly to your preferences and restart fitbit-steps.

⁠Sample configuration
---
### General options
# start of lunch
LUNCH_START: 12:00:00
# end of lunch
LUNCH_END: 13:00:00
# start of dinner
DINNER_START: 19:30:00
# end of dinner
DINNER_END: 20:30:00
# Number of minutes of variance from START and END times of meals
## Make sure this number is not going to overlap the START and END times (cannot have END before START)
MEAL_VARIANCE: 15
# cooldown before bed time
COOLDOWN: 120

### Workday-specific activities
# minimum steps per day
WORKDAY_STEPS_MINIMUM: 10000
# maximum steps per day
WORKDAY_STEPS_MAXIMUM: 15000
# Start of activities during workdays. Format: HH:MM:SS
# Set minimum to 00:00:00
WORKDAY_START: 07:00:00
# End of activities during workdays. Format: HH:MM:SS
# Set maximum to 23:59:59
WORKDAY_END: 23:00:00
# Number of minutes of variance from START and END times of workdays
# Make sure this number is not going to overlap the START and END times (cannot have END before START)
WORKDAY_VARIANCE: 30

### Weekend-specific activities
# minimum steps per day
WEEKEND_STEPS_MINIMUM: 14000
# maximum steps per day
WEEKEND_STEPS_MAXIMUM: 20000
# Start of activities during weekends. Format: HH:MM:SS
# Set minimum to 00:00:00
WEEKEND_START: 08:30:00
# End of activities during weekends. Format: HH:MM:SS
# Set maximum to 23:59:59
WEEKEND_END: 23:30:00
# Number of minutes of variance from START and END times of weekends
# Make sure this number is not going to overlap the START and END times (cannot have END before START)
WEEKEND_VARIANCE: 60

### Higher-intensity walk activities
# Optional: start of workday higher-intensity walk activity
WORKDAY_INTENSIVE_START: 17:00:00
# Optional: end of workday higher-intensity walk activity
# Required if WORKDAY_INTENSIVE_START is set
WORKDAY_INTENSIVE_END: 18:00:00

# Optional: start of weekend higher-intensity walk activity
WEEKEND_INTENSIVE_START: 14:30:00
# Optional: end of weekend higher-intensity walk activity
# Required if WORKDAY_INTENSIVE_START is set
WEEKEND_INTENSIVE_END: 16:30:00

# Number of minutes of variance from START and END times of high intensity activities
# Make sure this number is not going to overlap the START and END times (cannot have END before START)
INTENSIVE_VARIANCE: 20
...

⁠First time

The first time we run the app, we also have to insert the code obtained in the last step of the initialization, make sure you include a valid one in the ONETIME_CODE variable.

CODE is the access code obtained above.

Tag summary

Content type

Image

Digest

Size

10.2 MB

Last updated

almost 6 years ago

docker pull tsubus/fitbit-steps