我成功实现了授权步骤,我使用redirect_uri获取了代码值。和实现FitBit OAuth AccessToken请求(https://wiki.fitbit.com/display/API/OAuth+2.0)时 我收到以下错误:
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}
根据文档我提供了每个推荐值,代码如下:
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");
这里grant_type值是authorization_code Accesstoken_uri:https://api.fitbit.com/oauth2/token
任何人都可以解决这个问题吗?
答案 0 :(得分:1)
添加grant_type = authorization_code作为body参数而不是header参数。 您也可以将客户端ID和redirect_uri添加为正文参数。