02-25-2017 15:27 - edited 02-25-2017 15:28
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

02-25-2017 15:27 - edited 02-25-2017 15:28
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hey guys, I am trying to connect to the fitbit API via the server authorization code, I have my request URL as follows (I've replaced the client_id with a ****** for this post, my actual client_id is in there):
when I submit and allow the request I get the following error in a var dump of the response body.
string(83) "{"error":"invalid_client","error_description":"The client credentials are invalid"}"
I've re-copied and paste my client ID and secret from my fitbit app settings many times and still get the same error. I also searched the fitbit api docs for error with "The client credentials are invalid" in it and was not able to find anything listed with that error description.
Here is my code
<?php namespace OAuth2Demo\Client\Controllers; use Silex\Application; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Guzzle\Http\Client; class CoopOAuthController extends BaseController { public static function addRoutes($routing) { $routing->get('/coop/oauth/start', array(new self(), 'redirectToAuthorization'))->bind('coop_authorize_start'); $routing->get('/coop/oauth/handle', array(new self(), 'receiveAuthorizationCode'))->bind('coop_authorize_redirect'); }
public function redirectToAuthorization(Request $request) { $redirectUri = $this->generateURL( 'coop_authorize_redirect', array(), true ); $url = 'https://www.fitbit.com/oauth2/authorize?'.http_build_query(array( 'response_type' => 'code', 'client_id' =>'******', 'redirect_uri ' => $redirectUri, 'scope' => 'activity profile' )); // var_dump($url); return $this->redirect($url); } public function receiveAuthorizationCode(Application $app, Request $request) { // equivalent to $_GET['code'] $code = $request->get('code'); $redirectUri = $this->generateURL( 'coop_authorize_redirect', array(), true ); $http = new Client('http://coop.apps.knpuniversity.com', array( 'request.options' => array( 'exceptions' => false, ) )); /* 1. Get the Access Token */ $request = $http->post('/token', null, array( 'client_id' => '******', 'client_secret' => '*********************************', 'grant_type' => 'authorization_code', 'code' => $code, 'redirect_uri' => $redirectUri, )); // make a request to the token url $response = $request->send(); $responseBody = $response->getBody(true); var_dump($responseBody);die; $responseArr = json_decode($responseBody, true); $accessToken = $responseArr['access_token']; $expiresIn = $responseArr['expires_in']; $request = $http->get('/api/me'); $request->addHeader('Authorization', 'Bearer '.$accessToken); $response = $request->send(); echo $response->getBody();die; die('Implement this in CoopOAuthController::receiveAuthorizationCode'); } } ?>
Thanks for the help!
02-27-2017 17:02
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



02-27-2017 17:02
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
If you can provide the HTTP request, either in raw HTTP or recreated as a cURL request, we can help you.

02-27-2017 20:03
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

02-27-2017 20:03
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
curl 'http://localhost:9000/coop/oauth/handle?code=6ef296e5dcca03652e4fc155cf5b9549c52163b7' -H 'Accept-Encoding: gzip, deflate, sdch, br' -H 'Accept-Language: en-US,en;q=0.8' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Referer: http://localhost:8080/' -H 'Cookie: PHPSESSID=58cuqj8gjjrkumas5l4noluuo7' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' --compressed

02-28-2017 16:14
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



02-28-2017 16:14
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
That is a request to your application. What is the request your application makes to the Fitbit Web API?

