Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用gethealth api在laravel中获取当前日期google fit步骤计数?_Php_Laravel_Google Fit - Fatal编程技术网

Php 如何使用gethealth api在laravel中获取当前日期google fit步骤计数?

Php 如何使用gethealth api在laravel中获取当前日期google fit步骤计数?,php,laravel,google-fit,Php,Laravel,Google Fit,我开发了一个健身仪表盘。它显示用户当前一天的步数、卡路里消耗量、公里数。为此,我使用gethealth api。我可以正确获取以前的日期数据,但无法获取当前日期的数据。它返回空数组。请给我的其他选择gethealth也 以下步骤: 步骤1:在gethealth中创建帐户,使用accesstoken添加用户,并在mysql数据库中存储accesstoken 步骤2:使用为添加的用户获取设备,并从响应中获取连接url。发送给用户。这样,他们就可以将google fit与gethealth连接起来 步

我开发了一个健身仪表盘。它显示用户当前一天的步数、卡路里消耗量、公里数。为此,我使用gethealth api。我可以正确获取以前的日期数据,但无法获取当前日期的数据。它返回空数组。请给我的其他选择gethealth也

以下步骤:

步骤1:在gethealth中创建帐户,使用accesstoken添加用户,并在mysql数据库中存储accesstoken

步骤2:使用为添加的用户获取设备,并从响应中获取连接url。发送给用户。这样,他们就可以将google fit与gethealth连接起来

步骤3:使用

这些步骤是我一直遵循的。但我无法获取当前日期的数据。 我也尝试过同步api。但是没有用。 请帮帮我

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, 0);
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
                    curl_setopt($ch, 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;
}