01-03-2016 14:44 - edited 01-21-2016 10:38
01-03-2016 14:44 - edited 01-21-2016 10:38
I can not figure out this problem.
I have tried to make a http request for getting the acess token
but always fitbit say me this :
{"errors":[{"errorType":"invalid_request","message":"Authorization header required. Visit https://dev.fitbit.com/docs/oauth2 for more information on the Fitbit Web API authorization process."}],"success":false}I have used the following code to make the http request :
URL url = new URL("https://api.fitbit.com/oauth2/token");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Authorization", " Basic REDACTED");
conn.setRequestProperty( "Content-type", "application/x-www-form-urlencoded");
conn.setRequestProperty( "Accept", "*/*" );
OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
writer.write("client_id=my_client_id&scope=activity&code=my_code_recived");
writer.flush();
String line;
BufferedReader reader = new BufferedReader(new
InputStreamReader(conn.getInputStream()));
while ((line = reader.readLine()) != null) {
Log.i("operationOut",line);
}
writer.close();
reader.close();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
Can someone help me to resolve this problem?
I am sorry if my english is no perfect
PS:
it is for an android app
Moderator edit: I removed the value of your Authorization header, as you publicly posted your client secret. Please go to https://dev.fitbit.com/apps/ and reset your client secret by clicking the "Reset Consumer Key/Secret" button on your app's settings.
Answered! Go to the Best Answer.
01-21-2016 10:36 - edited 01-21-2016 10:40
01-21-2016 10:36 - edited 01-21-2016 10:40
Dear JeremiahFitbit,
I have finally found the solution at my problem.
The problem was about the class HttpURLConnection of java that did not add properly the property "Authentication" so I changed it using the class HttpClient and it work successfully in my case with Android Lollipop (5.0.2).
Thank you very much for your attention !
01-04-2016 17:40
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.
01-04-2016 17:40
I'm not familiar with Android development. Can you provide a capture of the actual HTTP request? You might use a tool like Runscope Traffic Inspector. Be sure to not publicly post your actual client credentials.
Best Answer01-21-2016 10:36 - edited 01-21-2016 10:40
01-21-2016 10:36 - edited 01-21-2016 10:40
Dear JeremiahFitbit,
I have finally found the solution at my problem.
The problem was about the class HttpURLConnection of java that did not add properly the property "Authentication" so I changed it using the class HttpClient and it work successfully in my case with Android Lollipop (5.0.2).
Thank you very much for your attention !
02-01-2016 00:28
02-01-2016 00:28
Hi Liam001,
Could you share android code?
And It will help many android-devs
07-28-2016 12:00
07-28-2016 12:00
Yeah for sure
Can you tell me exactly what you need?
PS:
Sorry for my bad English
Best Answer01-04-2018 15:45
01-04-2018 15:45
Hey Liam001, could you please share the android java code? I need it for my school project.
Best Answer01-04-2018 16:29 - edited 01-04-2018 16:30
01-04-2018 16:29 - edited 01-04-2018 16:30
Hi,
here are the steps I followed to get user data by using the Fitbit web API:
1) Use Chrome Customs Tabs: https://developer.chrome.com/multidevice/android/customtabs
2) It's very important to use a intent-filter so after using google custom tab you can redirect to your app with the token
3) Use a generic http request for android as : http://hc.apache.org/httpclient-3.x/tutorial.html
There is no a specific code but an entire workflow in order to make it work.
Best Answer02-27-2018 01:33 - edited 02-27-2018 01:35
02-27-2018 01:33 - edited 02-27-2018 01:35
Hi Liam,
I am also looking at OAuth2 with FitBit on Android. So far, I have tried with Spring Authentication and Scribe Library. I see you have just used HTTP Requests.
Have you implemented the Authorization Code Grant Flow?
If correct, this takes 4 HTTP requests:
- Authorization Code
- Access Token
- Refresh Token
- Revoke Token
Can you share your code for Chrome Custom Tabs please?
This would be very helpful..
Thanks and good luck!
Niels
Best Answer