Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
371 views
in Technique[技术] by (71.8m points)

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

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??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...