01-10-2016 20:56
01-10-2016 20:56
Hi, I am trying to integrate FitBit in my new application. I am currently using the implicit method to call the apis and everything works fine till the access token. The user logs in and I get his user id and access token. But the request after that fails every time.
I am pasting my function which I am using to make the call.
public static JSONObject getFitBit(String url, String accessToken){
URL u;
HttpURLConnection urlConnection = null;
JSONObject response = null;
int i = 0;
try {
u = new URL(url);
urlConnection = (HttpURLConnection) u.openConnection();
urlConnection.setUseCaches(false);
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
urlConnection.setRequestProperty("Authorization", "Bearer " + accessToken);
int responseCode = urlConnection.getResponseCode();
if(responseCode == HttpsURLConnection.HTTP_OK){
String responseString = readStream(urlConnection.getInputStream());
response = new JSONObject(responseString);
} else {
return null;
}
} catch (Exception e) {
return null;
}finally {
if(urlConnection != null)
urlConnection.disconnect();
}
return response;
}
Please look at it and tell me where am I going wrong.
01-11-2016 11:14
01-11-2016 11:14
Please do not paste large code blocks to the forum. Use a GitHub gist or link to a public repository.
We prefer to debug the actual HTTP request you're making to Fitbit, as it is much easier to identify issues. Please capture and share the HTTP request your application is making and the response from Fitbit. One tool to do this is Runscope Traffic Inspector. Be sure to obfuscate your access token when publicly sharing.