I need to get a list of recent activities in Google Fit, including the distance traveled.
I am using direct REST API requests (PHP via cURL).
- First, I do authorization via oAuth 2.0
After authorization, I'm redirected to my site %REDIRECT_URI%, where the GET request contains "code".
I use this "code" to get the auth token:
POST - https://www.googleapis.com/oauth2/v3/token
POST data: {
'code': %CODE_FROM_GET_PARAM%,
'client_id' => %CLIENT_ID%,
'client_secret' => %CLIENT_SECRET%,
'grant_type' => 'authorization_code',
'redirect_uri' => %REDIRECT_URI%
}
After completing the request, I receive an auth token of the form "ya29.a0ARrdaM-...", I use this token for header Bearer authorization.
I make a request https://www.googleapis.com/fitness/v1/users/me/sessions to get a list of activities:
"session": [
{
"id": "Run1629350880000",
"name": "Run",
"description": "",
"startTimeMillis": "1629350880000",
"endTimeMillis": "1629352020000",
"modifiedTimeMillis": "1629358291250",
"application": {
"packageName": "com.xiaomi.hm.health"
},
"activityType": 8
}, ...
]
Based on this list, I can see the running time (startTimeMillis, endTimeMillis), but I still need to get the distance.
What should I do next?