2

I Successfully Implemented the authorization step and i got the code value with redirect_uri. and while Implementing FitBit OAuth AccessToken Request (https://wiki.fitbit.com/display/API/OAuth+2.0) i am getting the following error:

WARN : org.apache.http.impl.client.DefaultHttpClient - Authentication error: Unable to respond to any of these challenges: {oauth=WWW-Authenticate: OAuth realm="https%3A%2F%2Fapi008-g4.prod.dal05.fitbit.com"}
{"errors":[{"errorType":"oauth","fieldName":"n/a","message":"invalid_request, Missing grant_type parameter value"}],"success":false}

as per document i supplied every recommended values and the code is like:

String authString = fitbit.getClient_id()+":"+fitbit.getClient_secret();
String authEncString = Base64.getEncoder().encodeToString(authString.getBytes());
url = fitbit.getAccesstoken_uri() + "?code="+code+"&grand_type="+fitbit.getGrant_type()+"&client_id="+fitbit.getClient_id()+
        "&redirect_uri="+fitbit.getRedirect_url();
String url3 = fitbit.getAccesstoken_uri();

HttpClient httpClient = new DefaultHttpClient();
HttpGet request = new HttpGet(url3);
request.addHeader("Authorization", "Basic " + authEncString);
request.addHeader("Content-Type","application/x-www-form-urlencoded");
request.addHeader("code", code);
request.addHeader("grant_type",fitbit.getGrant_type());
request.addHeader("client_id", fitbit.getClient_id());
request.addHeader("redirect_uri", fitbit.getRedirect_url());

    HttpResponse response = httpClient.execute(request);

    String json = EntityUtils.toString(response.getEntity(), "UTF-8");

Here grant_type value is authorization_code Accesstoken_uri : https://api.fitbit.com/oauth2/token

Can any one solve this?

  • I see a spelling mistake in your code. '&grand_type' should be '&grant_type' instead. It could be the issue – amishra Jul 17 '15 at 19:47
  • I corrected that spelling mistake, even though I am getting same error. Is grant_type value is authorization_code for OAuth 2.0? If no, what is the grant_type value. – chandra sekhar lagadapati Jul 18 '15 at 08:46

1 Answers1

1

Add grant_type=authorization_code as a body parameter instead of header parameter. You can add client id and redirect_uri also as a body parameter.

hybrid
  • 1,255
  • 2
  • 17
  • 42