The result returned by Garmin Health Api is an empty array
P粉842215006
P粉842215006 2023-08-30 16:53:05
0
1
508

When using Garmin's health API, I get an empty response array, no errors are displayed, and only an empty array is returned. I am confused and have not found any solution. My code is as follows:

;
public static function get_garmin_health_data(Request $request) { // dd(date('Y-m-d H:i:s')); $garmin_consumer_key = env('CONSUMERKEY'); $garmin_consumer_secret = env('CONSUMERSECRET'); $twitter_access_token = $request->oauth_token ?? ''; $twitter_access_token_secret = $request->oauth_token_secret ?? ''; $twitter_version = '1.0'; $sign_method = 'HMAC-SHA1'; date_default_timezone_set('Asia/kolkata'); // $end_time = Carbon::now()->timestamp; // Generate a timestamp similar to 1552296328 // $start_time = Carbon::now()->subDays(1)->timestamp; $start_time = strtotime('-20 hours'); $end_time = time(); // dd($start_time); // $time = $request->oauth_nonce; $time = time(); // $post = '{"event":{"type":"message_create","message_create":{"target":{"recipient_id":"123"},"message_data" :{"text":"Hello world"}}}}'; $post = '{}'; $url = 'https://apis.garmin.com/wellness-api/rest/dailies'; $param_string = 'oauth_consumer_key=' . $garmin_consumer_key . '&oauth_nonce=' . $time . '&oauth_signature_method=' . $sign_method . '&oauth_timestamp=' . $time . '&oauth_token=' . $twitter_access_token . '&oauth_version=' . $twitter_version . '&uploadEndTimeInSeconds=' . $end_time . '&uploadStartTimeInSeconds=' . $start_time; // 为POST生成签名基本字符串 $base_string = 'GET&' . rawurlencode($url) . '&' . rawurlencode($param_string); // dd($base_string); $sign_key = rawurlencode($garmin_consumer_secret) . '&' . rawurlencode($twitter_access_token_secret); // 生成唯一签名 $signature = base64_encode(hash_hmac('sha1', $base_string, $sign_key, true)); $curl_header = 'OAuth oauth_consumer_key="' . rawurlencode($garmin_consumer_key) . '", ' . 'oauth_nonce="' . rawurlencode($time) . '", ' . 'oauth_signature="' . rawurlencode($signature) . '", ' . 'oauth_signature_method="' . $sign_method . '", ' . 'oauth_timestamp="' . rawurlencode($time) . '", ' . 'oauth_token="' . rawurlencode($twitter_access_token) . '", ' . 'oauth_version="' . $twitter_version . '"'; $url2 = 'https://apis.garmin.com/wellness-api/rest/dailies?uploadStartTimeInSeconds=' . $start_time . '&uploadEndTimeInSeconds=' . $end_time; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $url2, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'Authorization:' . $curl_header, ), )); $response = curl_exec($curl); dd($response); curl_close($curl); $res = json_decode($response);

请为这个问题提供一个解决方案,如果可能的话,用PHP或CURL请求进行回答。

P粉842215006
P粉842215006

reply all (1)
P粉478188786

I'm also dealing with this Garmin-health API and getting a blank response (eg: []). But I think so! I don't have any activity in my profile so I'm getting this response.

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!