Google Fit get heart rate data

1k Views Asked by At

I would like to get my heart rate data stored on Google Fit. Through this page I can try the API: https://developers.google.com/fit/rest/v1/reference/users/dataSources/datasets/get?apix=true and work because the json result is:

{
  "minStartTimeNs": "1607036400000000000",
  "maxEndTimeNs": "1607122800000000000",
  "dataSourceId": "raw:com.google.heart_rate.bpm:AA:62:2a5297f4:Notify for Amazfit - heart rate",
  "point": [
    {
      "startTimeNanos": "1607036509703000000",
      "endTimeNanos": "1607036509703000000",
      "dataTypeName": "com.google.heart_rate.bpm",
      "value": [
        {
          "fpVal": 46,
          "mapVal": []
        }
      ],
      "modifiedTimeMillis": "1607076710847"
    },
...
...
...

If I click on the javascript tab it generates the code that must only be modified with API_KEY and CLIENT_ID but if I run it the result is:

minStartTimeNs  "1607036400000000000"
maxEndTimeNs    "1607122800000000000"
dataSourceId    "raw:com.google.heart_rate.bpm:com.mc.amazfit1:Amazfit:Amazfit Bip Watch:97f19a4a:Notify for Amazfit - heart rate"
point   []

The "point" array is empty. Without any errors, it doesn't tell me, that I don't have access, or the scope is wrong, it's just empty. Even looking with the firefox debugger the ajax calls are identical, only the access token changes. how can I do? thanks.

1

There are 1 best solutions below

0
On

I see you are using the device's datasource directly (Amazfit Bip watch), not the derived Google Fit datasource. When I tried accessing the device's datasources, I also saw no data returned. After much trial and error, I had better luck fetching it from the derived sources, examples below.

DATA_SOURCE = {
    "steps": "derived:com.google.step_count.delta:com.google.android.gms:merge_step_deltas",
    "dist": "derived:com.google.distance.delta:com.google.android.gms:from_steps<-merge_step_deltas",
    "bpm": "derived:com.google.heart_rate.bpm:com.google.android.gms:merge_heart_rate_bpm",
    "rhr": "derived:com.google.heart_rate.bpm:com.google.android.gms:resting_heart_rate<-merge_heart_rate_bpm",
    "sleep" : "derived:com.google.sleep.segment:com.google.android.gms:sleep_from_activity<-raw:com.google.activity.segment:com.heytap.wearable.health:stream_sleep",
    "cal" : "derived:com.google.calories.expended:com.google.android.gms:from_activities",
    "move": "derived:com.google.active_minutes:com.google.android.gms:from_steps<-estimated_steps",
    "points" : "derived:com.google.heart_minutes:com.google.android.gms:merge_heart_minutes",
    "weight" : "derived:com.google.weight:com.google.android.gms:merge_weight"
    }

Obviously, the only other time I have seen this happen (point []) is when there is no data for that timeframe, i.e. the datasetId (start-end). It is common with 'Heart Points' and 'Active Minutes'. But I wouldn't think that would be the case for heart rate data (unless you weren't wearing the watch).