问题描述
我开发了一个健身仪表板。它显示用户当前的步数、卡路里消耗、跨越的公里数。为此,我正在使用 gethealth api https://platform.gethealth.io/docs 。我可以正确获取以前的日期数据,但无法获取当前日期的数据。它返回空数组。也请给我一些 gethealth 的替代方案。
以下步骤:
步骤 1:在 gethealth 中创建帐户并使用 https://platform.gethealth.io/docs/#!/Account_API/CreateUser 添加用户并将 accesstoken 存储在 MysqL 数据库中
第 2 步:使用 https://platform.gethealth.io/docs/#!/Account_API/get_v1_health_user_devices 为添加的用户获取设备并从响应中获取连接 URL。发送给用户。这样他们就可以将 google fit 与 gethealth 联系起来。
第 3 步:使用 https://platform.gethealth.io/docs/#!/Health_Panel_API/post_v1_health_user_daily_summary
获取当天活动public function getMembers(){
$response_arr = array();
try{
$members = DB::table('users')
->select('user_id','name','email','role','get_health_id','get_health_access_token','profile_picture')
->where('status','A')
->get();
$curr_date = date('Y-m-d');
$st_date = $curr_date."T00:00:00";
$end_date = $curr_date."T23:59:59";
if(count($members) > 0){
foreach ($members as $member) {
$token = $member->get_health_access_token;
if(!empty($token)){
$url = "https://platform.gethealth.io/v1/health/user/daily_summary?";
$get_daily_data_params = array(
"access_token" => $token,"limit" => 100,"start_date" => $st_date,"end_date" => $end_date,"source" => "googlefit"
);
$params_str = http_build_query($get_daily_data_params);
$url .= $params_str;
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,CURLOPT_HTTPHEADER,array('Content-Type: application/json'));
$response = curl_exec($ch);
$daily_data_arr = json_decode($response,true);
curl_close($ch);
if(count($daily_data_arr['daily_summary']) > 0){
$member->google_fit_data = $daily_data_arr['daily_summary'][0];
}else{
$member->google_fit_data = "";
}
}
}
$response_arr['status'] = "success";
$response_arr['data'] = $members;
$response_arr['date'] = $curr_date;
}else{
$response_arr['status'] = "error";
$response_arr['message'] = "User Not Found";
}
} catch(Exception $e){
$response_arr['status'] = "error";
$response_arr['message'] = $e->getMessage();
}
return $response_arr;
}
这些步骤是我遵循的。但我无法获得当前日期的数据。 我也试过同步 api https://platform.gethealth.io/docs/#!/Account_API/post_v1_health_account_syncs。但没有用。 请帮帮我。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)