For HR/HRV data extraction
iPhone: https://apps.apple.com/jp/app/fitbit/id462638897
Android: https://play.google.com/store/apps/details?id=com.fitbit.FitbitMobile&hl=ja&gl=US&pli=1
Create an account at https://accounts.fitbit.com/signup
Most likely you have already created an account since the initial setup of your Fitbit device requires it. Please log in with that account.
Register your app at https://dev.fitbit.com/apps
You can check the app information later, so it is a good idea to bookmark it.
Click Register a new app in the upper right corner.
There are many fields for entering URLs, but if the program is just using requests to run the API, as in this case, the URL fields other than Redirect URL are fine with http://localhost
.
- Application Name: Any
- Description: Any 10 characters or more.
- Application Website URL:
http://localhost
- Organization: Any
- Organization Website URL:
http://localhost
- Terms of Service URL:
http://localhost
- Privacy Policy URL:
http://localhost
- OAuth 2.0 Application Type: Choose "Personal"
- Redirect URL:
http://localhost:8000
(Any available port) - Default Access Type: Choose "Read Only"
After pressing the "Register" button, the following page will be displayed.
The registered information is displayed, and the Client ID and Client Secret are issued.
This screen can be viewed at any time later.
Click "OAuth2.0 Tutorial" in the lower left corner to issue access token.
Issue an access token by following the instructions on the tutorial's web screen.
Note the two "Access Token" and "Refresh Token" that appear at the end.
Select "Client (for client-side access)" for Application Type.
Generate the information needed to issue an access token. Press the green Generate button in two places.
Two strings will be generated, but they are temporary and do not need to be kept.
Uncheck the items you do not allow to be retrieved from the API (optional).
Then click on Authorization URL.
The authorization page will open automatically.
Make sure there are no items you excluded earlier, check "Allow all" and press "Permission" button.
Then, http://localhost:8000/
specified in the Redirect URL will open.
You will see the message "This site cannot be accessed." Please copy the URL without closing it.
Paste the URL you have just entered in the red frame of the image below.
Then, the "Authorization Code" and "State" will be extracted from the URL and displayed.
There is no need to write down either of these values.
The request is automatically generated based on the URL above. Press the green button.
If no errors are displayed in the text area below, you are OK.
Be sure to note the Access Token and Refresh Token.
The Access Token is used to run the API. Refresh Token has a lifespan of 8 hours, so when it expires, the token is reissued using Access Token.
Save it under the name fb_conf.json
.
{
"client_id": "xxxxxx",
"client_secret": "xxxxxx",
"access_token": "xxxxxx",
"refresh_token": "xxxxxx"
}
Fill in the token obtained in 3. Issuance of access token.
"client_id" and "client_secret" can be found at https://dev.fitbit.com/apps by clicking on the registered app.
Since the access token is automatically renewed by the application, it does not matter if it has expired.
Run fitbit-api-python/app/update_token.ipynb
When you run it, place fb_conf.json
in the same directory.
When running in Google Colab, Ctrl+F9
will run all runtimes.
If the token has expired, the program will automatically update it and overwrite fb_conf.json
.
If the message "The request succeeded." is displayed, the API is working properly.
Run fitbit-api-python/app/get_heart_rate.ipynb
When you run it, place fb_conf.json
in the same directory.
Also, enter the date DATE
in cell 2 for which the data is to be retrieved.
When running in Google Colab, Ctrl+F9
will run all runtimes.
Download the csv when it is output.