3

Google documentation mentions about specifically writing Blood Pressure data: https://developers.google.com/fit/scenarios/write-bp-data

But it does not mention URL to be used for REST API to read Blood Pressure data? Is that Health data (Blood Pressure, Blood Glucose...) is not accessible via REST API and it is only limited to Fitness data (Calories, Steps, Distance...)

I was hopeful that REST API would be available for reading Blood Pressure so that I can try it out in OAuth Playground on how it works.

v.j
  • 186
  • 11
  • My question is specifically about reading Blood Pressure data. Is read also restricted? If not restricted then is there a REST API? – v.j Sep 06 '17 at 05:59
  • You may try with the HistoryAPI and check if the data type your looking for is available in the DataTypes param. If yes you can pass this to your readData. – Sanket Mendon Sep 06 '17 at 06:21
  • I see that TYPE_BLOOD_PRESSURE is not part of the fitness DataType...Its part of the HealthDataTypes. Will this still work? – v.j Sep 06 '17 at 07:28
  • Yes it will work. – Sanket Mendon Sep 06 '17 at 07:43
  • Thanks. Is there any restriction that only apps that can write BloodPressure data will be able to read BloodPressure data? – v.j Sep 06 '17 at 09:00
  • No. That restriction is only for writing. Set your scope in your client and your good to go. – Sanket Mendon Sep 06 '17 at 09:29
  • To reconfirm - Blood Pressure read can not be done via REST API but can be done using HistoryAPI of GooglePlayServices? – v.j Sep 07 '17 at 07:32
  • Yes should work – Sanket Mendon Sep 07 '17 at 10:26
  • Hey, were you able to read blood pressure? I'm also looking for the same. Thank you. – Anudeep Sep 25 '17 at 09:36
  • @Anu - I ran into other problems as I have to run it on AndroidTV but GooglePlayServices on AndroidTV do not support Google Fit APIs at all! – v.j Oct 03 '17 at 04:49
  • This might help, am not sure it will work so adding in the comment. Check this link: https://developers.google.com/fit/datatypes/restricted. It specifies the data type for reading blood pressure data like reading any other dataset. For ex: `Url: [link](https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate) Method: POST Body: { "aggregateBy": [{ "dataTypeName":"com.google.blood_pressure" }], "bucketByTime": { "durationMillis": 86400000 }, "startTimeMillis": 1579717800743, "endTimeMillis": 1580408999743 }` – Naman Khandelwal Feb 09 '20 at 11:59

1 Answers1

3

I'm aware that this is about REST, but I faced the same question on Android, so I'll post my solution here, it might be helpful to someone.

You need to treat Blood Pressure same as you treat other info you're pulling from Google Fit (i.e Steps, Weight...).

You need to add the following line to your fitness builder:

      FitnessOptions fitnessOptions = FitnessOptions.builder()
    ------> .addDataType(HealthDataTypes.AGGREGATE_BLOOD_PRESSURE_SUMMARY, FitnessOptions.ACCESS_READ)
            .addDataType(DataType.TYPE_WEIGHT, FitnessOptions.ACCESS_READ)
            .addDataType(DataType.TYPE_STEP_COUNT_DELTA, FitnessOptions.ACCESS_READ)
            .build();

And when you need to query it, use the following HealthDataType:

public Task<DataReadResponse> queryBloodPressureData(Activity activity, GoogleSignInAccount account) {
    return Fitness.getHistoryClient(activity, account)
            .readData(new DataReadRequest.Builder()
                    .aggregate(HealthDataTypes.TYPE_BLOOD_PRESSURE, HealthDataTypes.AGGREGATE_BLOOD_PRESSURE_SUMMARY)
                    .bucketByTime(1, TimeUnit.MINUTES)
                    .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
                    .build()
            );
}

For full details check the official documentation.

omzer
  • 1,200
  • 11
  • 14