【问题标题】:fitbit php auth doesn't workfitbit php 身份验证不起作用
【发布时间】:2015-08-05 20:29:00
【问题描述】:

在尝试了各种 fitbit php 库 10 小时后,我转向 stackoverflow 寻求帮助。

这不起作用:https://github.com/heyitspavel/fitbitphp

使用

 $profile = $fitbit->getProfile();

用那个库返回

Fatal error: Uncaught exception 'FitBitException' with message 'Your Fitbit request failed. Code: 400' in /var/www/api/fitbitphp.php:324 Stack trace: #0 /var/www/api/addFitbit.php(22): FitBitPHP->getProfile() #1 {main} thrown in /var/www/api/fitbitphp.php on line 324

Fitbit 网站上的这个库,好像很多人都有这个问题。

    public function getProfile()
{
    $headers = $this->getHeaders();

    try {
        $this->oauth->fetch($this->baseApiUrl . "user/" . $this->userId . "/profile." . $this->responseFormat, null, OAUTH_HTTP_METHOD_GET, $headers);
    } catch (Exception $E) {
    }
    $response = $this->oauth->getLastResponse();
    $responseInfo = $this->oauth->getLastResponseInfo();
    if (!strcmp($responseInfo['http_code'], '200')) {
        $response = $this->parseResponse($response);

        if ($response)
            return $response;
        else
            throw new FitBitException($responseInfo['http_code'], 'Fitbit request failed. Code: ' . $responseInfo['http_code']);
    } else {
        throw new FitBitException($responseInfo['http_code'], 'Your Fitbit request failed. Code: ' . $responseInfo['http_code']);
    }
}

我也在这里尝试过,但它没有返回用户令牌或会话 ID https://github.com/nostra999/fitbit-api

【问题讨论】:

    标签: php fitbit


    【解决方案1】:

    可能错过了初始化步骤,如 lib README 文件 (https://github.com/heyitspavel/fitbitphp/blob/master/README.md) 中所述

    简单的工作用法是:

    <?php
    define('FITBIT_KEY', '777'); // The application key registered
    define('FITBIT_SECRET', '777'); // The application secret registered
    
    $fitbit = new FitBitPHP(FITBIT_KEY, FITBIT_SECRET);
    $fitbit->initSession('http://localhost:8080/fibit'); // callback URL
    $fitbit->getProfile();
    

    同样来自 Fitbit API 文档: https://wiki.fitbit.com/display/API/API+Response+Format+And+Errors#APIResponseFormatAndErrors-Response

    400 Bad Request 任何一个端点都不存在的情况下,资源 路径参数无效,POST请求参数无效或没有 提供的身份验证标头。这不包括无效的具体 资源ID

    如果这没有帮助,请提供您运行的完整代码,而不仅仅是

    $profile = $fitbit->getProfile();

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-13
      • 2017-04-10
      • 1970-01-01
      • 1970-01-01
      • 2015-06-08
      • 2012-10-04
      相关资源
      最近更新 更多