Categorygithub.com/Thomas2500/go-fitbit
modulepackage
1.2.4
Repository: https://github.com/thomas2500/go-fitbit.git
Documentation: pkg.go.dev

# README

go-fitbit

Fitbit API for Go

The official docs do provide partially different data than provided by the API. This project uses the retuned data of the API as base instead of the official fields defined by the documentation. This fields do use omitempty to not break parsing. Partially some fields were added in the documentation but are still missing in the Swagger file provided by Fitbit.

Please note that you need to register an app on https://dev.fitbit.com/apps/new to receive an API key to use any functionality provided by this project. If you want to use the data only for yourself, you can use "Personal" as OAuth application type. This way the API allows access to intraday data like pulse data in second resolution. Otherwise, use "Server" as application type. You can view your existing apps including your credentials at https://dev.fitbit.com/apps.

This project is provided as-is and should be tested before using in any productive environment. Did I forgot something to implement, found a bug, something changed or recommendations? Please feel free to create an issue or a pull request!

Installation

This project can be used as a dependency of your project.

go get github.com/Thomas2500/go-fitbit

Example

You can find a working example how to use go-fitbit within the folder example/server/ which shows data of most API endpoints, shows how to use subscriptions and how to handle token updates.

Initialisizing a new API session can be done using the fitbit.Config struct. This will return a new API session.

// Create a new fitbit session
fca = fitbit.New(fitbit.Config{
  ClientID:     clientID,
  ClientSecret: clientSecret,
  RedirectURL:  fmt.Sprintf("https://%s/callback", "localhost"),
  Scopes: []string{
    fitbit.ScopeActivity,
    fitbit.ScopeBreathingRate,
    fitbit.ScopeHeartrate,
    fitbit.ScopeLocation,
    fitbit.ScopeNutrition,
    fitbit.ScopeProfile,
    fitbit.ScopeSettings,
    fitbit.ScopeSleep,
    fitbit.ScopeSocial,
    fitbit.ScopeSpO2,
    fitbit.ScopeTemperature,
    fitbit.ScopeWeight,
  },
})

Notes

As of https://dev.fitbit.com/build/reference/web-api/basics/#numerical-ids all IDs should be considered as unsigned int64.

TODO

Some functions arn't tested because I do not have the hardware for it (I'm only using a Fitbit Versa 1 and MobileTrack of the iPhone app). If you have hardware which provides additional data (alarms, temperature, or Fitbit Aria) please test the functionality and let me know if everything works or something needs to be changed.

Functioons explicitly not tested (eventually broken, please test!) or not finished yet:

Further to do:

  • combine similar structs and highlight differences

Findings

  • /1/foods/locales.json returns imageUpload true on en_US, but not with other languages like de_DE. No description how it can be used.
  • Food search does only return PUBLIC records and no custom stored records. I found no way to find my own records or use them.

What I use this API for

I do save the fetched data into MariaDB & InfluxDB databases for further processing and a simple overview in Grafana. My plan for the future is to further process the data and combine it with other sources of data like weather, movie seen, music listened to, public travel vs driving with car, ... The possibilities are endless and I do have currently enough free storage to store everything :-)

Big thanks to Fitbit for providing such great devices and API access to the generated data! Unfortunately, this is not a matter of course in the fitness and health sector, although it should be.

# Packages

No description provided by the author

# Functions

New creates a new fitbit oauth session.
No description provided by the author

# Constants

Different types of useable scopes.
Different types of useable scopes.
Different types of useable scopes.
Different types of useable scopes.
Different types of useable scopes.
Different types of useable scopes.
Different types of useable scopes.
Different types of useable scopes.
Different types of useable scopes.
Different types of useable scopes.
Different types of useable scopes.
Different types of useable scopes.
Different types of useable scopes.
Different types of useable scopes.

# Structs

ActiveZoneMinutesDay contains the active zone minutes for a given day.
No description provided by the author
ActivitiesFrequent contains an activity from frequent call.
ActivitiesGoal contains the activities goal of an user.
ActivitiesHeartIntraday intraday data.
ActivitiesInterdayLog contains user activity logs for the given day in intraday accuracy.
ActivitiesIntradaySingleRecord contains a single record of an intraday activity.
ActivitiesLifetime contains the account lifetime statistics.
ActivitiesLog contains user activity logs, only one dataset is used and the other ones are empty.
ActivitiesLogList contains the activity log list.
ActivitiesLogSingleRecord contains a single record of an activity.
ActivitiesSummaryDay contains a summary of activities of a requested day.
ActivitiesTypes contains a list of activities.
AddFoodLogResponse defines the response of AddFood request.
Badge contains information about a badge.
BadgesList contains a list of badges.
BodyFat contains one or multiple records, similar to BodyFat but without weight.
BodyFatGoal contains the currently set fat goal of the user.
BodyWeight contains one or multiple records.
BodyWeightGoal contains the currently set body goal by the user.
No description provided by the author
No description provided by the author
CardioFitnessScoreLog contains the cardio fitness score (VO2Max) for a given date.
Config describes the configuration of a fitbit API configuration.
Device contains information about a fitbit device.
ECG data.
FoodEntry contains a food entry.
FoodGoal contains the food goal of a user.
FoodLog contains a users food log.
FoodSearchResult contains a list of food found by FoodSearch.
FoodWaterLogDateRange contains a summary of calories or water for a given date range.
Friend describes a friend.
FriendsInvitations contains a list of open invitations to the user.
FriendsLeaderboard contains the leaderboard of a user.
FriendsList contins a list of friends.
ActivityTCX contains the activity TCX for a given activity Fitbit is using http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2 for the TCX format Also available at https://www8.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd TODO: Extend struct below to include all available fields.
HeartDay contains a summary of heartrates for a given date range.
HeartIntraday with slightly different structure to HeartDay.
HeartRateVariabilityIntraday with slightly different structure to HeartRateVariabilitySummary.
HeartRateVariabilitySummary contains a summary of heartrate variability (HRV) values for a given date range.
HeartRateZones contains the heart rate zones of different types like cardio.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
IntrospectResponse contains the response of the introspect request.
LogListParameters contains parameters for the activity log list.
NewActivity contains the data for a new activity nolint:lll.
NewActivityResponse contains the response from a new activity request.
NewFoodLog defines the data to be sent to the API when adding a new food log entry.
Profile contains profile information of an user.
Ratelimit includes the rate limit information provided on every request.
Session is the main object with user data.
SleepDay contains data of a sleep day.
SleepGoal defines the structure of SleepGoal response.
SleepLogList defines the structure of SleepLogList based on an response.
No description provided by the author
No description provided by the author
Subscription contains response and request data of fitbit eventsx.
SubscriptionList contains a list of current active subscriptions.
No description provided by the author
No description provided by the author
WaterGoal describes the water goal of the user.
WaterLog contains the water log of a user.

# Type aliases

FoodCollectionList contains a list of food collections.
FoodLocales contains a list of supported food locales.
FoodUnits defines the response of FoodUnits request.
Scope describes an oauth2 scope for Fitbit.