How I Built My Own Fitness Tracker Using Google Fit Data
How I Quickly Built an App That Could Keep Track of Fitness Data in a Spreadsheet
I recently was contracted for a freelance assignment on Fiverr to pull data from the Google Fit API for a client in Switzerland. Specifically, I was tasked with retrieving 3 key fields: steps walked per day, calories expended per day, and distance traveled (in km) and in this article I will walk through the steps to deliver this project.
About Google Fit:
Google Fit is Google’s own service for keeping track of your health data. It integrates with many different types of watches and fitness trackers and aggregates your data in one place. It keeps track of things like Steps Walked, Your Weight, and Your Heart Rate. It has a nice interface and is fairly easy to use. It’s only available as a mobile app.
While I browsed the documentation of the Google Fit API, I saw that Google has extensive documentation for this API and tons of examples of code.
API Setup:
Below are the instructions of how to properly setup the app:
Also, while Google’s documentation is very detailed, it did not have specifics about how to call the API in a particular programming language. Since I was building my app in Google Sheets, I would have to use JavaScript to make the calls and display the data.
I was plotting how I could effectively accomplish this task when while Google searching I came across a stellar article about how to use the Google Fit API. Detailed blogs and tutorials like this are what I love about the community on the Internet.
This blog was called “I Thought He Came With You” and was an excellent resource––I encourage you to check the link here. The author of the article has given the code to get back 3 fields. I needed 3 different fields; specifically, I needed
(1) steps per day
(2) calories expended per day and
(3) distance walked in km. The code gets written in Google Script Editor and looks like this:
There is further processing needed to correctly print the response in the Google sheet. The end product looks beautiful:
Potential Uses of This Data Besides Simple Tracking:
As we can see this is a very rich and interesting data source at our disposal now. With workout analytics, it is possible to graph for all sorts of insights related to when and why certain fitness parameters are reached on certain days.
It would also be possible to use this data to create a personal scoring system about fitness levels. A runner may want to keep track of miles ran per day, per week, or per month and automate the call to Google Fit with this handy API. A weight lifter could keep track of length of workouts per day. A biker could keep track of miles biked.
Also this data can be used to keep track of weight as part of a weight loss program. Ultimately, you would need a very specific use case to want to have this data in tabular format in a Google sheet versus in the Google Fit app.
Conclusion:
Today, we see a proliferation of workout related apps. However, as I have demonstrated here, it is possible to create one’s own workout data app with a bit of inspiration and some code in a spreadsheet––accessing and working with workout data can help build healthier people which leads to a healthier world.