1

错误是,

stdClass Object
(
    [errors] => Array
        (
            [0] => stdClass Object
                (
                    [errorType] => oauth
                    [fieldName] => n/a
                    [message] => No Authorization header provided in the request. Each call to Fitbit API should be OAuth signed
                )

        )

)

我正在使用 Oauth 库。我已经获得了用户令牌。

http://api.fitbit.com/1/user/23Q/profile.json?oauth_consumer_key=425e1234b8823e26485aa6&oauth_nonce=31f991c9b3e068c14adceddd9b862c0a&oauth_signature=R5oi4dHA6ztIIpdKheahYOy%2FeMQ%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1348821623&oauth_token=3405b4918d5d96a7b78885a98&oauth_version=1.0

我试过这个...

$url = http://api.fitbit.com/1/user/23Q2SP/profile.json

$标头=数组();
$header[] = "授权:OAuth 3405b496578885a98";

$header[] = "Accept: ";

$header[] = "Cache-Control: no-cache";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en_US";
$header[] = "Pragma: no-cache";   
$this->http_info = array();
$ci = curl_init();
/* Curl settings */
curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent);
curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);
curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ci, CURLOPT_HTTPHEADER, $header);
curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
curl_setopt($ci, CURLOPT_HEADER, FALSE);

curl_setopt($ci, CURLOPT_URL, $url);
$response = curl_exec($ci);

但是相同的错误 {"errors":[{"errorType":"oauth","fieldName":"n/a","message":"请求中没有提供授权标头。对 Fitbit API 的每次调用都应该是 OAuth签”}]}

4

2 回答 2

1

我没有使用 Fitbit API,但我在这里读到的是,Fitbit 只允许通过授权标头进行 GET 请求,因此您可能必须设置标头类似

"Authorization: OAuth <ACCESS_TOKEN>" http://www.fitbit.com

查看这篇关于如何通过 CURL 设置标题的帖子,希望对您有所帮助。

于 2012-09-28T09:57:44.570 回答
0

试试这个:

req_url = 'http://api.fitbit.com/oauth/request_token';
$authurl = 'http://api.fitbit.com/oauth/access_token';
$acc_url = 'http://api.fitbit.com/oauth/authorize';

$conskey = 'Dev key';
$conssec = 'Dev secret';

$token = 'User token';
$secret = 'User secret';



try {

    $oauth = new OAuth($conskey,$conssec,OAUTH_SIG_METHOD_HMACSHA1,OAUTH_AUTH_TYPE_AUTHORIZATION);
    $oauth->enableDebug();



     $oauth->setToken($token,$secret);


      $oauth->fetch("http://api.fitbit.com/1/user/-/activities/date/2013-12-06.json");
    $response_info = $oauth->getLastResponseInfo();

  print_r($oauth->getLastResponse());

  } catch(OAuthException $E) {
  print_r($E);
}
于 2013-12-14T22:36:15.073 回答