11-14-2015 07:29
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-14-2015 07:29
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I have done the authentication successfully. But now I don't know of how to make a API call.
I use this php-class:
$provider = new djchen\OAuth2\Client\Provider\Fitbit([
In an example I found this:
$endpoint = $provider->getBaseApiUrl() . "user/-/activities/heart/date/today/1d." . FitBit::FORMAT_JSON;
but, I get an error 500.
Can somebody point me in the right direction?
Answered! Go to the Best Answer.
Accepted Solutions
11-17-2015 18:07 - edited 11-17-2015 18:13
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-17-2015 18:07 - edited 11-17-2015 18:13
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
There are other libraries you could use as well as djchens oauth2 implementation.
I've also created an oauth2.0 provider for fitbit (https://github.com/jmitchell38488/oauth2-fitbit)
Do you know what the 500 server error is? You need to add the access token to the request so that the server can authenticate you.
For example (with my provider):
$endpoint = $provider->getBaseApiUrl() . "user/-/profile." . FitBit::FORMAT_JSON;
// endpoint: https://api.fitbit.com/1/user/-/profile.json $provider = new FitBit([ 'clientId' => $my_client_id_from_fitbit, 'clientSecret' => $my_client_secret_from_fitbit, 'redirectUri' => $my_callback_url, ]); $request = $provider->getAuthenticatedRequest( FitBit::METHOD_GET, $endpoint, $_SESSION['fitbit']['oauth2']['accessToken'] ); $response = $provider->getResponse($request);
Server 500 error could mean a number of different things. There isn't much we can do without a full error log.

11-16-2015 15:05
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

SunsetRunner
11-16-2015 15:05
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I suggest you open an issue on Github with the project for support:

11-17-2015 18:07 - edited 11-17-2015 18:13
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-17-2015 18:07 - edited 11-17-2015 18:13
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
There are other libraries you could use as well as djchens oauth2 implementation.
I've also created an oauth2.0 provider for fitbit (https://github.com/jmitchell38488/oauth2-fitbit)
Do you know what the 500 server error is? You need to add the access token to the request so that the server can authenticate you.
For example (with my provider):
$endpoint = $provider->getBaseApiUrl() . "user/-/profile." . FitBit::FORMAT_JSON;
// endpoint: https://api.fitbit.com/1/user/-/profile.json $provider = new FitBit([ 'clientId' => $my_client_id_from_fitbit, 'clientSecret' => $my_client_secret_from_fitbit, 'redirectUri' => $my_callback_url, ]); $request = $provider->getAuthenticatedRequest( FitBit::METHOD_GET, $endpoint, $_SESSION['fitbit']['oauth2']['accessToken'] ); $response = $provider->getResponse($request);
Server 500 error could mean a number of different things. There isn't much we can do without a full error log.

02-26-2016 13:48
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

02-26-2016 13:48
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Is there a solution in plain PHP for this? I've spent hours looking already!
In short, I can get through authorization just fine.. but when I try to get actual data, I get nothing back!!!
define("client_id",'xxx');
define("client_secret",'xxx');
define("response_type",'code');
define("scope", 'activity');
define("redirect_uri", 'xxx');
$code = $_GET['code']; $url = "https://api.fitbit.com/oauth2/token"; $auth_header = array("Authorization: Basic " . base64_encode(client_id.":".client_secret), "Content-Type: application/x-www-form-urlencoded"); $access_token_setttings = array( 'code' => $code, 'grant_type' => "authorization_code", 'client_id' => client_id, 'redirect_uri' => redirect_uri ); $curl = curl_init($url); curl_setopt($curl, CURLOPT_HTTPHEADER, $auth_header); curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($access_token_setttings)); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $result = curl_exec($curl); curl_close(); $results = json_decode($result, true); //var_dump($result); echo $results['user_id'];
The above code works fine.. I get a reply with an access_token, expires_in, and refresh_token ... but how do I get actual data? When I make a php JASON call with the code below, I get nothing.
$newURL = 'https://api.fitbitcom/1/user/'.$results['user_id'].'/activities/date/2016-02-26.json';
I tried searching everything, here, github, etc.. thanks!

02-20-2018 22:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

02-20-2018 22:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hi ptsChris,
Were you able to get your PHP code working?
Thanks,
Tim

