简体   繁体   中英

How to get daily step count and active calories from google fitness store via Fitness REST API

I am using nodejs and Google's official "googleapis" module. I am unable to get any value field from any data source.

var count = 0;
               async.eachSeries(dataSources, function (source, nextSource) {
                   count++;
                   console.log(count, source.dataStreamId);
                   console.log('------------------------------------------------------------------------------------------------------------------------------');
                   fitness.users.dataSources.datasets.get({
                       dataSourceId: encodeURI(source.dataStreamId),
                       datasetId: new Date('2016-01-01').getTime() + '-' + new Date().getTime(),
                       userId: "me"
                   }, function (err, data) {
                       if (err) {
                           console.log(err);
                           return nextSource(err);
                       }
                       console.log("Data Set");
                       console.log(data);
                       nextSource(null);
                   });
               }, function nextSource(err) {
                   if (err) {
                       return nextTask(err);
                   }
                   nextTask(null, 'OK')
               });

All I get in response is something like:

{ minStartTimeNs: '1451606400000',
  maxEndTimeNs: '1455532058239',
  dataSourceId:   
  'derived:com.google.step_count.delta:com.google.android.gms:estimated_steps' 
}

I had the same problem, but find the sollution.

"minStartTimeNs: '1451606400000', maxEndTimeNs: '1455532058239'"

They are not in the correct format, the api need epoch time in NANOSECOND (19 number), so its need to 1451606400000000000 and 1455532058239000000

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM