Access to Fitbit API with Scala

The developer API of Fitbit provides access to the data collected by it’s personal trackers for use with custom applications development. Besides read also write access can be used not only to it’s own but on behalf of other platform users via OAuth authentication. A comprehensive documentation of the Fitbit API can be found here: .

In an attempt to collect my own data for exploration I created this little sample project using OAuth2 to connect to my own data. For OAuth to work it needs to be registered as an application at Fitbit. Also the user needs to visit the OAuth authorization page of Fibit to authorize the application for data access.

At the end I use Json4s to parse the response body obtaining the required access_token, refresh_token, and user_id. The XPath access method seems convenient, but maybe not as efficient calling it for every single value.

Having now all needed credentials to obtain the data for my own user we can make use of the Fitbit API for example for Activities. As a sample call we will try to fetch the activity information of one day given as a parameter. The expected output should look like this:

For simplicity we are only interested in some of the summary values here, but this time we will map them to a object using Json4s which can be easily achieved with case classes if the attribute names correspond to the once defined in the result JSON. The object definition:

Requesting the activities becomes a fairly simple implementation using the above mapping together with the prior requested access token of the user together with it’s id.

Last we are going to use SBT for a sample execution:

Further Reading

One thought on “Access to Fitbit API with Scala”

Leave a Reply

Your email address will not be published. Required fields are marked *