I have selected 'OAuth 2.0 Application Type' as 'Client' and 'Flow Type' as 'Authorization Code Flow'
I am able to get the authorization code, but unable to get 'Access Token' using authorization code. I am trying it from an asp.net we application.
My Code as follows:
Url for code : (Generated by fitbit wesite)
"https://www.fitbit.com/oauth2/authorize?response_type=code&client_id=xxxx&redirect_uri=https://local... respiratory_rate&expires_in=604800";
string code = Request.Params["code"];
string code_verifier = "01234567890123456789012345678901234567890123456789";
var authoken = Base64Encode("2xxxxx" + ":" + "axxxxxxxxxxxxxxxxxxxxxxxx");
var url = "https://api.fitbit.com/oauth2/token";
var client = new RestClient(url);
var request = new RestRequest(url, Method.Post);
request.AddHeader("Authorization", "Basic " + authoken);
var body = new
{
clientid = "2xxxxx",
code = code,
code_verifier = code_verifier,
grant_type = "authorization_code",
};
var bodyy = JsonConvert.SerializeObject(body);
request.AddBody(bodyy, "application/x-www-form-urlencoded");
RestResponse response = client.Execute(request);
var output = response.Content;
Response :
{"errors":[{"errorType":"invalid_request","message":"Missing 'grant_type' parameter value.
Visit https://dev.fitbit.com/docs/oauth2 for more information on the Fitbit Web API authorization process."}],"success":false}
Note : If I try with the suggested approach in documentation
POST https://api.fitbit.com/oauth2/token Content-Type: application/x-www-form-urlencoded client_id=ABC123&code=<authorization_code>&code_verifier=<code_verifier>&grant_type=authorization_code
I am getting 'Invalid Authorization'
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
Are you specifying the header
Authorization: Basic <basic_token>?
Best AnswerHi Gordon,
thanks for the replay,
Yes, I am sending a base64 encoded value of '(ClientId : Client Secret) as mentioned in documentation.
You can see that in my code above like this "request.AddHeader("Authorization", "Basic " + authoken);"
-ragards
Best Answer
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
Are you still receiving the error ""Missing 'grant_type' parameter value." If so, would you please reproduce the error again, and private message me your client ID so I can search our logs to determine what is going on.
Best Answer