问题
I am trying to get data from Google Fit using REST API. I am able to get individual data points for steps and calories through the documented REST APIs. However,I want them aggregated by day. I see the following resource in the Oauth2 playground:
https://www.googleapis.com/fitness/v1/users/{userId}/dataset:aggregate
However, I was not able to find any documentation on how to use this. Has anyone been successful in using this REST resource? Any pointers to the documentation / any examples would really help.
Thanks,
回答1:
This is how i solved this REST call & its working code in my project.
$AccessToken = "TOKEN";
Data['aggregateBy'] =array(["dataTypeName"=>'com.google.step_count.delta',"dataSourceId"=>'derived:com.google.step_count.delta:com.google.android.gms:estimated_steps']);
$Data['bucketByTime']['durationMillis'] =86400000;
$Data['startTimeMillis'] =1487721600000;
$Data['endTimeMillis'] =1487772000000;
$JsonData = json_encode($Data);
$ApiUrl = 'https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate?access_token='.$AccessToken;
$Ch = curl_init();
curl_setopt($Ch, CURLOPT_URL, $ApiUrl);
curl_setopt($Ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($Ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($Ch, CURLOPT_HEADER, 0);
curl_setopt($Ch, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
curl_setopt($Ch, CURLOPT_POST, 1);
curl_setopt($Ch, CURLOPT_POSTFIELDS, $JsonData);
$Result = curl_exec($Ch);
curl_close($Ch);
print_r($Result);
来源:https://stackoverflow.com/questions/34694278/documentation-for-google-fit-rest-api-datasetaggregate