Created
August 22, 2018 09:02
-
-
Save sugyan/9d8ba84ea0695a1ea406792c1cb75908 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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