Garmin Health Api返回的结果为空数组
P粉842215006
P粉842215006 2023-08-30 16:53:05
[PHP讨论组]
<p>使用Garmin的健康健康API时,获取到空的响应数组,不显示任何错误,只返回一个空的数组,我很困惑,没有找到任何解决方案,我的代码如下:</p> <pre class="brush:php;toolbar:false;">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-&gt;oauth_token ?? ''; $twitter_access_token_secret = $request-&gt;oauth_token_secret ?? ''; $twitter_version = '1.0'; $sign_method = 'HMAC-SHA1'; date_default_timezone_set('Asia/kolkata'); // $end_time = Carbon::now()-&gt;timestamp; // 产生类似于1552296328的时间戳 // $start_time = Carbon::now()-&gt;subDays(1)-&gt;timestamp; $start_time = strtotime('-20 hours'); $end_time = time(); // dd($start_time); // $time = $request-&gt;oauth_nonce; $time = time(); // $post = '{&quot;event&quot;:{&quot;type&quot;:&quot;message_create&quot;,&quot;message_create&quot;:{&quot;target&quot;:{&quot;recipient_id&quot;:&quot;123&quot;},&quot;message_data&quot;:{&quot;text&quot;:&quot;Hello world&quot;}}}}'; $post = '{}'; $url = 'https://apis.garmin.com/wellness-api/rest/dailies'; $param_string = 'oauth_consumer_key=' . $garmin_consumer_key . '&amp;oauth_nonce=' . $time . '&amp;oauth_signature_method=' . $sign_method . '&amp;oauth_timestamp=' . $time . '&amp;oauth_token=' . $twitter_access_token . '&amp;oauth_version=' . $twitter_version . '&amp;uploadEndTimeInSeconds=' . $end_time . '&amp;uploadStartTimeInSeconds=' . $start_time; // 为POST生成签名基本字符串 $base_string = 'GET&amp;' . rawurlencode($url) . '&amp;' . rawurlencode($param_string); // dd($base_string); $sign_key = rawurlencode($garmin_consumer_secret) . '&amp;' . rawurlencode($twitter_access_token_secret); // 生成唯一签名 $signature = base64_encode(hash_hmac('sha1', $base_string, $sign_key, true)); $curl_header = 'OAuth oauth_consumer_key=&quot;' . rawurlencode($garmin_consumer_key) . '&quot;, ' . 'oauth_nonce=&quot;' . rawurlencode($time) . '&quot;, ' . 'oauth_signature=&quot;' . rawurlencode($signature) . '&quot;, ' . 'oauth_signature_method=&quot;' . $sign_method . '&quot;, ' . 'oauth_timestamp=&quot;' . rawurlencode($time) . '&quot;, ' . 'oauth_token=&quot;' . rawurlencode($twitter_access_token) . '&quot;, ' . 'oauth_version=&quot;' . $twitter_version . '&quot;'; $url2 = 'https://apis.garmin.com/wellness-api/rest/dailies?uploadStartTimeInSeconds=' . $start_time . '&amp;uploadEndTimeInSeconds=' . $end_time; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL =&gt; $url2, CURLOPT_RETURNTRANSFER =&gt; true, CURLOPT_ENCODING =&gt; '', CURLOPT_MAXREDIRS =&gt; 10, CURLOPT_TIMEOUT =&gt; 0, CURLOPT_FOLLOWLOCATION =&gt; true, CURLOPT_HTTP_VERSION =&gt; CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST =&gt; 'GET', CURLOPT_HTTPHEADER =&gt; array( 'Authorization:' . $curl_header, ), )); $response = curl_exec($curl); dd($response); curl_close($curl); $res = json_decode($response);</pre> <p>请为这个问题提供一个解决方案,如果可能的话,用PHP或CURL请求进行回答。</p>
P粉842215006
P粉842215006

全部回复(1)
P粉478188786

我也在处理这个Garmin-health API,并且得到了空白的响应(例如:[])。 但是我想是这样的!我在我的个人资料中没有任何活动,所以我得到了这个响应。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号