【问题标题】:Fitbit Web API error grant typeFitbit Web API 错误授权类型
【发布时间】:2017-03-03 11:04:10
【问题描述】:

下面是api报的错误

{"errors":[
   {
     "errorType": "invalid_request",
     "message": "Missing 'grant_type' parameter value."
   }
], "success": false}

//curl request to fetch token with use of auth code used in my code

$curl = curl_init();
curl_setopt_array($curl, array(

    CURLOPT_RETURNTRANSFER => 1,

CURLOPT_URL => 'https://api.fitbit.com/oauth2/token',
CURLOPT_HTTPHEADER => array(
  'Authorization:Basic'.base64_encode(FITBIT_CLIENT_ID.':'.FITBIT_CLIENT_SECRET),
'Content-Type: application/x-www-form-urlencoded'
),
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
    'code' => $auth_code,
    'client_id' => FITBIT_CLIENT_ID,
    'grant_type' => "authorization_code", //auth code received in url params
    'redirect_uri' => 'https://www.example.com/auth/fitbit/success'
)
));
$resp = curl_exec($curl);
curl_close($curl);

我收到此错误。请帮助确定哪里可能是错误。

【问题讨论】:

    标签: php curl libcurl fitbit


    【解决方案1】:

    用 包裹您的帖子字段的数组以确保您正在执行编码(以防特殊字符)。

    CURLOPT_POSTFIELDS => http_build_query (array(
    ...
    ))
    

    尝试在授权标头之间放置一个空格。标准一用Authorization: Basic

    如果仍然看到错误,请在您的 curl 请求中使用 VERBOSE 模式。并使用该详细输出更新您的问题,以便我们为您提供帮助。

    【讨论】:

    • 是的,当我们将 postfields 输入作为字符串而不是数组时!它工作正常。所以 http_build_query 会解决这个问题。谢谢
    猜你喜欢
    • 2018-08-12
    • 2012-07-20
    • 1970-01-01
    • 2019-12-31
    • 2018-07-01
    • 2022-08-04
    • 2017-12-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多