5

I am struggling with matching the "active time" returned by Fit REST API with reality.

As an example - on 12/14 I had two walks, about 45 minutes each. The api returns one of them as type 7 ("walking" - right!) and another one as type 0 (in vehicle - wrong!). However, Fit app shows both as "walking", so it apparently uses a different data source.

I checked some other days and on these days, the session with type 0 is indeed a valid "in vehicle" session.

I tried all aggregated data sources that return com.google.activity.segment. Most of them are empty, I've found data only in merge_activity_segments and platform_activity_segments (and they seem to be identical).

Google's docs have a caveat about delay in data sync, but they never specified how long this delay is. The data I am looking at is about 24 hours old - if their sync is that slow, then this API is more or less unusable.

I am using the following POST to https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate

{
    "aggregateBy": [
        {
            "dataSourceId": "derived:com.google.activity.segment:com.google.android.gms:merge_activity_segments"
        }
    ],
    "endTimeMillis": "1481788800000",
    "startTimeMillis": "1481702400000",
    "bucketByTime": {
        "period": {
            "timeZoneId": "America/Los_Angeles",
            "type": "day",
            "value": 1
        }
    }
}

For reference - activity types: https://developers.google.com/fit/rest/v1/reference/activity-types

Has anyone been able to retrieve activity time from Fit's REST API that is correct? Any suggestions?

By the way, steps and calories seem to work fine - just aggregate the following datasets:derived:com.google.calories.expended:com.google.android.gms:merge_calories_expended and derived:com.google.step_count.delta:com.google.android.gms:estimated_steps

A side note - it is probably the worst documented API from a major company I have seen.

AlexR
  • 240
  • 1
  • 11

1 Answers1

0

I know it's been a while but maybe some other people will also find this topic later. It looks like not much changed in the documentation itself but I have found a following to work.

Active Minutes

Req Body

{
  "aggregateBy": [{
    "dataTypeName": "com.google.active_minutes",
    "dataSourceId": "derived:com.google.active_minutes:com.google.android.gms:merge_active_minutes"
  }],
  "bucketByTime": { "durationMillis": 86400000 },
  "startTimeMillis": 1678406400000,
  "endTimeMillis":1678579200000
}

URL

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

Type: POST

So what you basically do is first you call this URL: https://www.googleapis.com/fitness/v1/users/me/dataSources as GET request and you get the list of possible data sources. From there you copy the name for dataTypeName, and dataStreamId for dataSourceId. That's all, once you have those for the given data parameter you want to fetch, you just exchange the given values and call the first POST endpoint. Of course, don't forget about selecting the data range.

Pawel
  • 43
  • 2