Reputation: 29
Error is,
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
)
)
)
I am using Oauth library. I have already got user token.
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
I tried this...
$url = http://api.fitbit.com/1/user/23Q2SP/profile.json;
$header = array();
$header[] = "Authorization: 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);
BUT THE SAME ERROR {"errors":[{"errorType":"oauth","fieldName":"n/a","message":"No Authorization header provided in the request. Each call to Fitbit API should be OAuth signed"}]}
Upvotes: 1
Views: 1851
Reputation: 36
Try this one :
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);
}
Upvotes: 0
Reputation: 178
I haven't worked with Fitbit API, but what I read here is that, Fitbit allow GET requests only through authorization header, so you might have to set header something like
"Authorization: OAuth <ACCESS_TOKEN>" http://www.fitbit.com
check this post on how to set headers through CURL, hope that helps.
Upvotes: 1