Skip to content

Instantly share code, notes, and snippets.

@sugyan
Created August 22, 2018 09:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sugyan/9d8ba84ea0695a1ea406792c1cb75908 to your computer and use it in GitHub Desktop.
Save sugyan/9d8ba84ea0695a1ea406792c1cb75908 to your computer and use it in GitHub Desktop.
package main
import (
"context"
"encoding/json"
"log"
"golang.org/x/oauth2"
"golang.org/x/oauth2/fitbit"
)
func main() {
conf := oauth2.Config{
ClientID: "******",
ClientSecret: "********************************",
Endpoint: fitbit.Endpoint,
Scopes: []string{"activity", "heartrate", "profile", "settings", "social"},
}
token := &oauth2.Token{
AccessToken: "*******************************************************************************************************************************************************************************************************************************************************",
TokenType: "Bearer",
RefreshToken: "****************************************************************",
}
client := conf.Client(context.Background(), token)
res, err := client.Get("https://api.fitbit.com/1/user/-/activities/steps/date/today/1w.json")
if err != nil {
log.Fatal(err)
}
defer res.Body.Close()
var result struct {
ActivitiesSteps []struct {
DateTime string `json:"dateTime"`
Value string `json:"value"`
} `json:"activities-steps"`
}
if err := json.NewDecoder(res.Body).Decode(&result); err != nil {
log.Fatal(err)
}
for _, steps := range result.ActivitiesSteps {
log.Printf("%v: %v steps", steps.DateTime, steps.Value)
}
}
2018/08/22 17:58:11 2018-08-16: 0 steps
2018/08/22 17:58:11 2018-08-17: 0 steps
2018/08/22 17:58:11 2018-08-18: 0 steps
2018/08/22 17:58:11 2018-08-19: 0 steps
2018/08/22 17:58:11 2018-08-20: 0 steps
2018/08/22 17:58:11 2018-08-21: 0 steps
2018/08/22 17:58:11 2018-08-22: 5826 steps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment