Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Error retrieving access token

ANSWERED

Hi Folks,

I am coding using node js and have sccessfully retrieved the authorisation code and am attempting get the access token following the example in the documentation.

POST https://api.fitbit.com/oauth2/token
Authorization: Basic Y2xpZW50X2lkOmNsaWVudCBzZWNyZXQ=
Content-Type: application/x-www-form-urlencoded

client_id=22942C&grant_type=authorization_code&redirect_uri=http%3A%2F%2Fexample.com%2Ffitbit_auth&code=1234567890

At this point I just wanted to log the returned body containing the access token etc out via console.log() with the code I currently have as

var url = "https://www.fitbit.com/oauth2/token/client_id=mine&grant_type=authorization_code&redirect_uri=http://myredirect/oauth_callback&code=" + authorisation_code;
    var headers = {'Authorization': 'Basic' + " " + base64_clientid_andSecret,
    		'Content-Type': 'application/x-www-form-urlencoded'
    };
    var options = {url : url,
    				method: 'POST',
    				headers: headers
    		};
   console.log("URL:"+ url);
   console.log("headers:" + JSON.stringify(headers));
    request(options, function (error, response, body) {
            if (!error && response.statusCode == 200) {
                var jsonObject = JSON.parse(body);
                console.log("AccessToeknStuff:" + body);
   		});

I am not sure I have got the "client_id=mine&grant_type=authorization_code&redirect..." part in the correct location but can't see where else to put it.  My log is showing other items I have logged out in prior bits of code but not the console.log("AccessToeknStuff:" + body) indicating it is not getting to this step.

Any thoughts on this please.

 

Regards

 

Binway

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

I believe I have worked out the problem.

The code below needs to go into the body.

client_id=22942C&grant_type=authorization_code&redirect_uri=http%3A%2F%2Fexample.com%2Ffitbit_auth&code=1234567890

And the url should be api.fitbit.com NOT www.fitbit.com.

 

Thanks.

View best answer in original post

Best Answer
0 Votes
1 REPLY 1

I believe I have worked out the problem.

The code below needs to go into the body.

client_id=22942C&grant_type=authorization_code&redirect_uri=http%3A%2F%2Fexample.com%2Ffitbit_auth&code=1234567890

And the url should be api.fitbit.com NOT www.fitbit.com.

 

Thanks.

Best Answer
0 Votes