Search code examples
restapigoogle-fit

Return Height from Google Fit Rest API


Trying to get the latest height captured on Google Fit by a user for a web app. Using the https://developers.google.com/fit/rest/ I got the below.

const scopes = [
  'https://www.googleapis.com/auth/plus.me',
  'https://www.googleapis.com/auth/fitness.body.read'
];

const fitness = google.fitness('v1');

const gfHeight = await fitness.users.dataSources.get({
  userId: 'me',
  dataSourceId: '',
  datasetId: '',
});

console.log(gfHeight.data);

Returns the log below which is just details of the data source:

...
{dataStreamId: 'raw:com.google.weight:com.google.android.apps.fitness:user_input',
    dataStreamName: 'user_input',
    type: 'raw',
    dataType: { name: 'com.google.height', field: [[Object]] },
  application: { packageName: 'com.google.android.apps.fitness' },
  dataQualityStandard: []
}]}

On adding the datasets to datasource it returns a 404 so not sure how to structure the request to get an object containing the height.

const gfHeight = await fitness.users.dataSources.datasets.get... 

Solution

  • Try the tutorial here which uses the Fit API data-types as reference.

    get body height Endpoint:

    https://www.googleapis.com/fitness/v1/users/me/dataSources/derived:com.google.height:com.google.android.gms:merge_height/datasets/-
    

    Alternative: /users/me/dataSources/raw:com.google.height:com.google.android.apps.fitness:user_input/datasets/-

    Reference: https://developers.google.com/fit/rest/v1/data-types

    description

    This description relates to the primary endpoint above, for merged data points. This endpoint returns all of the body height data points that were synced to the Google Fit platform from devices connected to Google Fit. The body height values are returned as floating point numbers with a unit of meters. Each datapoint has a start datetime (startTimeNanos) and end datetime (endTimeNanos) and although they are likely the same, we will need to check that before creating the data point. The nanos values are unix epoch nanoseconds that are aligned to UTC.