How to get step count from Google Fit REST API like Google Fit app?

Kahn picture Kahn · Jan 17, 2015 · Viewed 12.9k times · Source

I'm developing a PHP application which work with Google Fit APIs to collect daily user's step count.

I want to get my step count from "Jan 15 2015 00:00:00 GMT+0700" to "Jan 16 2015 00:00:00 GMT+0700". - First, I get all my datasources. - Then, with each datasource which have datatype equal to "com.google.step_count.delta", I get datasets between above timestamps and add return values together.

My code: https://gist.github.com/daitr-gu/472c4f18522172542cca
My result: https://gist.github.com/daitr-gu/1a7e11eb483a657bdc8b

I found that, there are many datasources and they returns different values. And the values are too different from what I see in Google Fit app on my phone.

Questions:
1. Which datasource the Google Fit app use to calculate step count?
2. Why there are different between datasources's value and Google Fit value?
3. How can I get the Google Fit value?

Answer

Gouri Joshi picture Gouri Joshi · May 5, 2015
  1. Which datasource the Google Fit app use to calculate step count?

Google Fit App uses the estimated_steps data source to calculate step counts. DataSourceId: derived:com.google.step_count.delta:com.google.android.gms:estimated_steps

  1. Why there are different between datasources's value and Google Fit value?

Each data source represents a different device/source. I see you have a Sony Smart Watch and a HTC Desire connected to Google Fit. Each of your devices reports values to Fit which are merged together. Merge_step_deltas gives you the merged stream of all your step counters. Estimated_steps also takes into account activity, and estimates steps when there are none.

  1. How can I get the Google Fit value?

REST API can only access data which has been synced to the backend. To get same values as Google Fit, read estimated_steps data source. It should be the same as what you see on https://fit.google.com/. The device could have latest values which are not yet synced to the server. We are working on making the syncs and the cross-platform experience more seamless.

-- Engineer on Google Fit Team.