11-06-2022 09:09
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-06-2022 09:09
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hi everyone, I just released a couple of Go packages I extracted from a Go project I'm currently working on.
I'm developing an application that depends on the data collected by a [Fitbit device](https://www.fitbit.com/). This data is accessible through the [Fitbit Web API](https://dev.fitbit.com/build/reference/web-api/) by creating an OAtuh2 server application.
I created two packages:
1. [galeone/fitbit](https://github.com/galeone/fitbit). It allows you to create a server application and it completely handles the [Authorization Code Grant Flow with PKCE](https://dev.fitbit.com/build/reference/web-api/developer-guide/authorization/#Authorization-Code-Gra...). (you need to use a web framework and use the available method as shown in the README). This package also contains the `client` that implements - in idiomatic Go - almost all the GET requests to the API. Every request returns a Go struct with the correct data type, and it also handles the `TCX` format for the GPS-tracked activities.
2. [galeone/fitbit-pgdb](https://github.com/galeone/fitbit-pgdb). The OAuth2 authorization flow of the previous package requires a storage. I defined in the fitbit package a `Storage` interface and this is the implementation for PostgreSQL.
I hope the Gopher's community finds this useful.
​
That said, here's my call for collaborators 🙂
As I said, I developed these packages while developing another application that requires only fetching data - so the client implements (almost) all the GET endpoints of the Fitbit Web API.
If someone is interested, it could be a nice contribution to this project the implementation of all the other endpoints, for the POST and DELETE methods. I created 2 dedicated issues: [fitbit#3](https://github.com/galeone/fitbit/issues/3) [fitbit#4](https://github.com/galeone/fitbit/issues/4)
Moreover, since I don't track nutrition and I don't have access to the [Intraday GET APIs](https://dev.fitbit.com/build/reference/web-api/intraday/), there are 2 additional potential contributions: [fitbit#1](https://github.com/galeone/fitbit/issues/1) [fitbit#2](https://github.com/galeone/fitbit/issues/2)
​
If you're willing to contribute, let's get in touch! Pull requests (even outside of the issues - if you find some bug or there's something to improve) are welcome!
11-07-2022 11:49
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



11-07-2022 11:49
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hi @pgaleone
Thanks for posting your sample code in the community forums. This could be a good addition to our documentation code sample page, https://dev.fitbit.com/build/reference/web-api/developer-guide/libraries-and-sample-code/, since we don't have a Go example. If you're open to having us list it in our documentation, I have 2 questions for you.
- Besides the issues you listed in your post, does the code work out of the box, as is?
- Are the instructions in the readme simple and complete enough to help a novice developer in Go get the code running? I ask this because we have a wide-variety of developer skills in this forum.
If you would like to add the intraday endpoints, here the instructions for accessing your own intraday data.
- Go to http://dev.fitbit.com/apps
- Select your application, the press the "Edit Application Settings" button.
- Change your "application type" value to "personal" and save the changes.
Now, your application will be able to query your own intraday data (aka the application owner).
Best,
Gordon
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google

11-07-2022 11:59
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-07-2022 11:59
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hi @Gordon-C
Sure, I'd be happy if you list it in your documentation code sample page!
1. Yes, the code works as is. It's designed for the creation of an OAuth2 server application, and thus it requires the user to implement a web server as explained in the documentation. In Go, the creation of a web server is straightforward, and there are several web frameworks easy to use. Since it depends on a "Storage" the user has the option to use the storage I created based on PostgreSQL or implement its own Storage.
2. If the developer knows how to use a web framework (like Gin or echo), then yes, the content of the README is enough. Of course, without this prerequisite, it could be a bit painful. But I guess it's a mandatory prerequisite because, after all, there's always a redirection to a redirect_uri.
About the intraday requests, if I register the application as "personal" will the OAuth2 flow be the very same flow I implemented for the Server application? If yes, then great. I'll do it and I generate the correct Go types and the methods for the Intraday endpoints in the next few days

11-07-2022 12:21
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



11-07-2022 12:21
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hi @pgaleone
Thank you for confirming my 2 questions.
Yes, the authorization flow is the same when the application type = "personal". The only thing that is different is the ability to query someone else's data. After you have generated the Go code for the intraday endpoints, you can change the application type back to "server".
Thanks!
Gordon
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google

11-12-2022 03:54
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-12-2022 03:54
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hi @Gordon-C
I just added the personal endpoint requests: https://github.com/galeone/fitbit/commit/81d6a64a59891ab0d4bf4cc8cf365ab2d590a3ae
The package now supports to GET of everything, except for the nutrition data.
If you want, you can add this client to the list 🙂
I hope to find someone here that's willing to contributo to this client, for implementing the GET of the nutritrions endpoint, and the POST/DELETE for everything else.

11-14-2022 08:38
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



11-14-2022 08:38
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Thanks @pgaleone
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google

