Garmin wellness-api - 无效的 OAuth 签名 - PHP

问题描述

我在为 Garmin Wellness API 生成 oAuth 签名时遇到问题。

    $oauth_nonce = 'OhJBVADBAC8';
    $oauth_timestamp = '1614947339';
    $date_from = 1607089161;
    $date_to = 1614865161;

    $url = 'https://apis.garmin.com/wellness-api/rest/backfill/activities?summaryStartTimeInSeconds=' . $date_from . '&summaryEndTimeInSeconds=' . $date_to;

    $base_string = 'GET&' . rawurlencode($url) . '&' . rawurlencode('oauth_consumer_key=' . $oauth_consumer_key . '&oauth_nonce=' . $oauth_nonce . '&oauth_signature_method=' . $oauth_signature_method . '&oauth_timestamp=' . $oauth_timestamp . '&oauth_token=' . $oauth_token . '&oauth_version=' . $oauth_version . '&summaryStartTimeInSeconds=' . $date_from . '&summaryEndTimeInSeconds=' . $date_to);

    $oauth_signature = hash_hmac("SHA1",$base_string,$oauth_consumer_secret,false);
    $oauth_signature = rawurlencode(base64_encode(pack('H*',$oauth_signature)));

    $curl = curl_init();

    curl_setopt_array($curl,array(
        CURLOPT_URL => $url,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: OAuth oauth_consumer_key="' . $oauth_consumer_key . '",oauth_token="' . $oauth_token . '",oauth_signature_method="' . $oauth_signature_method . '",oauth_timestamp="' . $oauth_timestamp . '",oauth_nonce="' . $oauth_nonce . '",oauth_version="' . $oauth_version . '",oauth_signature="' . $oauth_signature . '"'
        ),));

    $response = curl_exec($curl);
    var_dump($response);
    curl_close($curl);

API 返回“无效的 OAuth 签名”。当我把Pastman生成的签名放上去时,一切正常,所以问题出在我生成签名的方式上。

你能指出我的错误吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)