1

I want to get all the activities registered in my google fit account between two dates (automatically registered ones such as walking and the rest) with all their information. I have spent some hours reading the Google Fit Rest API documentation, but I don't understand it well, so I can't obtain the desired data.

I don't know if the documentation of the API is messy, if there are few examples or if I don't understand it as my native language is not English (problably), but I don't understand how to do the calls.

If I am right:

  1. Google Fit API divides the type of data in 4 types: Sessions, data sources, data sets and data points.
  2. A session represents one activity.
  3. One datasource has many datasets and each dataset has many datapoints.

I want to retrieve all my activities between a period of time and with all the data for each activity(steps, calories, speed, heartrate, location, device that recorded the activity) in a Json.

What I have achieved

If I want to retrieve all my activities I can call:

Call

GET https://www.googleapis.com/fitness/v1/users/me/sessions.

  • I can use startTime and endTime to limit the sessions to retrieve.

The call response is:

{
    "session": [
        {
            "id": "ef3107ca-a132-43df-ba87-5767bdb2e832",
            "name": "nadar",
            "description": "",
            "startTimeMillis": "1643155200000",
            "endTimeMillis": "1643160600000",
            "modifiedTimeMillis": "1643195812287",
            "application": {
                "packageName": "com.google.android.apps.fitness"
            },
            "activityType": 82
        },
        {
            "id": "21195d09-bc89-4457-8293-039839808526",
            "name": "cicl",
            "description": "",
            "startTimeMillis": "1643161800000",
            "endTimeMillis": "1643163600000",
            "modifiedTimeMillis": "1643189389446",
            "application": {
                "packageName": "com.google.android.apps.fitness"
            },
            "activityType": 14
        },
        {
            "id": "be9f60b4-79e9-41d5-bf64-e366b63d86ef",
            "name": "Bailar",
            "description": "Mal",
            "startTimeMillis": "1609647420000",
            "endTimeMillis": "1609656420000",
            "modifiedTimeMillis": "1643224174323",
            "application": {
                "packageName": "com.google.android.apps.fitness"
            },
            "activityType": 24
        },
        {
            "id": "bef8bda8-b24e-4d04-a22a-86338e6049fe",
            "name": "danza",
            "description": "",
            "startTimeMillis": "1643185566914",
            "endTimeMillis": "1643187366914",
            "modifiedTimeMillis": "1643188254598",
            "application": {
                "packageName": "com.google.android.apps.fitness"
            },
            "activityType": 24
        },
        {
            "id": "6e72bdbd-4ce2-47cc-b857-4ab3487a6cc7",
            "name": "boxeo1",
            "description": "",
            "startTimeMillis": "1643168460000",
            "endTimeMillis": "1643170260000",
            "modifiedTimeMillis": "1643220544876",
            "application": {
                "packageName": "com.google.android.apps.fitness"
            },
            "activityType": 20
        },
        {
            "id": "e36f5557-2f76-44d3-a80e-464d5a7f6fb4",
            "name": "boxeo2",
            "description": "",
            "startTimeMillis": "1643212744367",
            "endTimeMillis": "1643218144367",
            "modifiedTimeMillis": "1643220544876",
            "application": {
                "packageName": "com.google.android.apps.fitness"
            },
            "activityType": 20
        },
        {
            "id": "2625516e274d7f96:activemode:baseball:1643225867610",
            "name": "béisbol por la tarde",
            "description": "",
            "startTimeMillis": "1643225867647",
            "endTimeMillis": "1643225875355",
            "modifiedTimeMillis": "1643226008584",
            "application": {
                "packageName": "com.google.android.apps.fitness"
            },
            "activityType": 11
        },
        {
            "id": "0f1d829e-22e0-4f79-b23f-04e60af95dbc",
            "name": "sdch",
            "description": "",
            "startTimeMillis": "1643186984290",
            "endTimeMillis": "1643188784290",
            "modifiedTimeMillis": "1643189389446",
            "application": {
                "packageName": "com.google.android.apps.fitness"
            },
            "activityType": 12
        },
       ...
    ],
    "deletedSession": [],
    "nextPageToken": "XmRh-ZWj_CZxgJml3CJjZQ"
}

With that data I can obtain the Google's fit main page activity list data (Except red squared activities and information). I can obtain the start date with "startTimeMillis", the name with "name", the duration substracting "startTimeMillis" and "endTimeMillis".

Authomatic steps activitries are not returned with this GET call and the "heart points" neither. ¿How can I obtain that data?

enter image description here

Then, I want to get all the data for each activity (blue squares data).

enter image description here enter image description here

To achieve that, I use the following POST call (I have achieved trhat response by test fail, as I don't understand properly each param of the body of the post call):

Call

POST https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate

Body

 {
   "aggregateBy": [
          {
            "dataTypeName": "com.google.calories.expended",
          }, {
            "dataTypeName": "com.google.step_count.delta",
          }, 
          {
            "dataTypeName": "com.google.speed",
          },
           {
            "dataTypeName": "com.google.active_minutes",
          },
           {
            "dataTypeName": "com.google.distance.delta",
          },
           {
            "dataTypeName": "com.google.heart_minutes",
          },
          ],
    "startTimeMillis": 1643151600000,
    "endTimeMillis": 1643238000000,
    bucketBySession: {}
}

What I understand about that body is that I want to retrive data packaged by session (activity) between"startTimeMillis" and "endTimeMillis". So, If two activities of the same type are done in that period, both will appear in the response. For each session (activity) package, I want to retrieve calories, steps, speed, minutes, distance and heart minutes (heart points).

The result is something like:

{
    "bucket": [
        {
            "startTimeMillis": "1643155200000",
            "endTimeMillis": "1643160600000",
            "dataset": [
                {
                    "dataSourceId": "derived:com.google.calories.expended:com.google.android.gms:aggregated",
                    "point": [
                        {
                            "startTimeNanos": "1643155200000000000",
                            "endTimeNanos": "1643160600000000000",
                            "dataTypeName": "com.google.calories.expended",
                            "originDataSourceId": "raw:com.google.calories.expended:com.google.android.apps.fitness:user_input",
                            "value": [
                                {
                                    "fpVal": 600,
                                    "mapVal": []
                                }
                            ]
                        }
                    ]
                },
                {
                    "dataSourceId": "derived:com.google.step_count.delta:com.google.android.gms:aggregated",
                    "point": []
                },
                {
                    "dataSourceId": "derived:com.google.speed.summary:com.google.android.gms:aggregated",
                    "point": [
                        {
                            "startTimeNanos": "1643157900000000000",
                            "endTimeNanos": "1643157900000000000",
                            "dataTypeName": "com.google.speed.summary",
                            "originDataSourceId": "raw:com.google.distance.delta:com.google.android.apps.fitness:user_input",
                            "value": [
                                {
                                    "fpVal": 0.55555558204650879,
                                    "mapVal": []
                                },
                                {
                                    "fpVal": 0.55555558204650879,
                                    "mapVal": []
                                },
                                {
                                    "fpVal": 0.55555558204650879,
                                    "mapVal": []
                                }
                            ]
                        }
                    ]
                },
                {
                    "dataSourceId": "derived:com.google.active_minutes:com.google.android.gms:aggregated",
                    "point": [
                        {
                            "startTimeNanos": "1643155200000000000",
                            "endTimeNanos": "1643160600000000000",
                            "dataTypeName": "com.google.active_minutes",
                            "originDataSourceId": "raw:com.google.active_minutes:com.google.android.apps.fitness:user_input",
                            "value": [
                                {
                                    "intVal": 90,
                                    "mapVal": []
                                }
                            ]
                        }
                    ]
                },
                {
                    "dataSourceId": "derived:com.google.distance.delta:com.google.android.gms:aggregated",
                    "point": [
                        {
                            "startTimeNanos": "1643155200000000000",
                            "endTimeNanos": "1643160600000000000",
                            "dataTypeName": "com.google.distance.delta",
                            "originDataSourceId": "raw:com.google.distance.delta:com.google.android.apps.fitness:user_input",
                            "value": [
                                {
                                    "fpVal": 3000,
                                    "mapVal": []
                                }
                            ]
                        }
                    ]
                },
                {
                    "dataSourceId": "derived:com.google.heart_minutes.summary:com.google.android.gms:aggregated",
                    "point": [
                        {
                            "startTimeNanos": "1643155200000000000",
                            "endTimeNanos": "1643160600000000000",
                            "dataTypeName": "com.google.heart_minutes.summary",
                            "value": [
                                {
                                    "fpVal": 180,
                                    "mapVal": []
                                },
                                {
                                    "intVal": 90,
                                    "mapVal": []
                                }
                            ]
                        }
                    ]
                }
            ],
            "session": {
                "id": "ef3107ca-a132-43df-ba87-5767bdb2e832",
                "name": "nadar",
                "description": "",
                "startTimeMillis": "1643155200000",
                "endTimeMillis": "1643160600000",
                "modifiedTimeMillis": "1643195812287",
                "application": {
                    "packageName": "com.google.android.apps.fitness"
                },
                "activityType": 82
            }
        },
        {
            "startTimeMillis": "1643161800000",
            "endTimeMillis": "1643163600000",
            "dataset": [
                {
                    "dataSourceId": "derived:com.google.calories.expended:com.google.android.gms:aggregated",
                    "point": [
                        {
                            "startTimeNanos": "1643161800000000000",
                            "endTimeNanos": "1643163600000000000",
                            "dataTypeName": "com.google.calories.expended",
                            "originDataSourceId": "raw:com.google.calories.expended:com.google.android.apps.fitness:user_input",
                            "value": [
                                {
                                    "fpVal": 200,
                                    "mapVal": []
                                }
                            ]
                        }
                    ]
                },
                {
                    "dataSourceId": "derived:com.google.step_count.delta:com.google.android.gms:aggregated",
                    "point": []
                },
                {
                    "dataSourceId": "derived:com.google.speed.summary:com.google.android.gms:aggregated",
                    "point": [
                        {
                            "startTimeNanos": "1643162700000000000",
                            "endTimeNanos": "1643162700000000000",
                            "dataTypeName": "com.google.speed.summary",
                            "originDataSourceId": "raw:com.google.distance.delta:com.google.android.apps.fitness:user_input",
                            "value": [
                                {
                                    "fpVal": 11.111110687255859,
                                    "mapVal": []
                                },
                                {
                                    "fpVal": 11.111110687255859,
                                    "mapVal": []
                                },
                                {
                                    "fpVal": 11.111110687255859,
                                    "mapVal": []
                                }
                            ]
                        }
                    ]
                },
                {
                    "dataSourceId": "derived:com.google.active_minutes:com.google.android.gms:aggregated",
                    "point": [
                        {
                            "startTimeNanos": "1643161800000000000",
                            "endTimeNanos": "1643163600000000000",
                            "dataTypeName": "com.google.active_minutes",
                            "originDataSourceId": "raw:com.google.active_minutes:com.google.android.apps.fitness:user_input",
                            "value": [
                                {
                                    "intVal": 30,
                                    "mapVal": []
                                }
                            ]
                        }
                    ]
                },
                {
                    "dataSourceId": "derived:com.google.distance.delta:com.google.android.gms:aggregated",
                    "point": [
                        {
                            "startTimeNanos": "1643161800000000000",
                            "endTimeNanos": "1643163600000000000",
                            "dataTypeName": "com.google.distance.delta",
                            "originDataSourceId": "raw:com.google.distance.delta:com.google.android.apps.fitness:user_input",
                            "value": [
                                {
                                    "fpVal": 20000,
                                    "mapVal": []
                                }
                            ]
                        }
                    ]
                },
                {
                    "dataSourceId": "derived:com.google.heart_minutes.summary:com.google.android.gms:aggregated",
                    "point": [
                        {
                            "startTimeNanos": "1643161800000000000",
                            "endTimeNanos": "1643163600000000000",
                            "dataTypeName": "com.google.heart_minutes.summary",
                            "value": [
                                {
                                    "fpVal": 30,
                                    "mapVal": []
                                },
                                {
                                    "intVal": 30,
                                    "mapVal": []
                                }
                            ]
                        }
                    ]
                }
            ],
            "session": {
                "id": "21195d09-bc89-4457-8293-039839808526",
                "name": "cicl",
                "description": "",
                "startTimeMillis": "1643161800000",
                "endTimeMillis": "1643163600000",
                "modifiedTimeMillis": "1643189389446",
                "application": {
                    "packageName": "com.google.android.apps.fitness"
                },
                "activityType": 14
            }
        },
        ...
        }
    ]
}

I don't know if it is the best way to achieve the activities data as I don't understand the API documentation. So, what I am asking is about a propper and a clean way to achieve the information of each activity and the authomatically recorded activities (i don't want the erased ones) and a little about explanation about it. I would also want to get the device that recorded each activity.

More doubts: Which is the difference between a datasourceName and datasourceId? Why is all so confusing?

When I try to use some dataTypeName such as: com.google.activity.exercise, com.google.activity.summary....in the body of my calls I get the following error and I can't understand why.

{
    "error": {
        "code": 400,
        "message": "no default datasource found for: com.google.activity.summary",
        "errors": [
            {
                "message": "no default datasource found for: com.google.activity.summary",
                "domain": "global",
                "reason": "invalidArgument"
            }
        ],
        "status": "INVALID_ARGUMENT"
    }
}
Jaime
  • 181
  • 2
  • 19
  • "Authomatic steps activitries are not returned with this GET call and the "heart points" neither. ¿How can I obtain that data?" A session is really just a marker of a portion of time, saying "between (start time) and (end time), user was doing (activity)". That's all. If you want to know other data, you need to read it from the specific data source for that type of data, e.g. using [get](https://developers.google.com/fit/rest/v1/reference/users/dataSources/datasets/get). If you want multiple types of data, you'd need to make multiple calls. – Andy Turner Jan 27 '22 at 18:23
  • "A session ir a marker of a portion of time user was doing an activity". So, is there any way to get the datasources of an specific session and get the data of that session? For example, if a session is of activity type boxing, how can I get the datasources of that session in order to take the data I want? What is wrong with my post call? – Jaime Jan 27 '22 at 19:54
  • @AndyTurner I would like to get from the rest API a json with a list of activities (authomatic and non authomatic ones) between a range of time. For each activity object, the steps, calories, speed, duration, device info (f.e Xiaomi MI 8, smartwatch), heart information, heart points, title of the activity, active minutes, distance and so on. I have tried to use the Users,datasources.datasets.get but it only retrieves the information of an specific datasource without saying the session it is linked to, so I get information but I can't know wich activity is related to the information. – Jaime Jan 28 '22 at 08:00
  • @AndyTurner I would like to get a response symilar to [Strava](https://developers.strava.com/docs/reference/#api-Activities-getLoggedInAthleteActivities) or to [Fitbit](https://dev.fitbit.com/build/reference/web-api/activity/get-activity-log-list/) one with all the activities (authomatic tracked activities, user inserted and so on). Please, could yo help me? – Jaime Jan 28 '22 at 08:07
  • Something new about this? – Jaime Feb 03 '22 at 22:12
  • did you found any solution for it ? I have noticed the same ...... activityType is int for ex. 7, 8, 10 but i need activity type name like running , walk, cycling , etc – Rajesh Koshti Jan 17 '23 at 10:52

0 Answers0