01-03-2016 14:44 - edited 01-21-2016 10:38
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-03-2016 14:44 - edited 01-21-2016 10:38
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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.
Accepted Solutions
01-21-2016 10:36 - edited 01-21-2016 10:40
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-21-2016 10:36 - edited 01-21-2016 10:40
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
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
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



01-04-2016 17:40
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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.

01-21-2016 10:36 - edited 01-21-2016 10:40
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-21-2016 10:36 - edited 01-21-2016 10:40
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
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
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

02-01-2016 00:28
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
Hi Liam001,
Could you share android code?
And It will help many android-devs
07-28-2016 12:00
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

07-28-2016 12:00
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Yeah for sure
Can you tell me exactly what you need?
PS:
Sorry for my bad English

01-04-2018 15:45
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-04-2018 15:45
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hey Liam001, could you please share the android java code? I need it for my school project.

01-04-2018 16:29 - edited 01-04-2018 16:30
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-04-2018 16:29 - edited 01-04-2018 16:30
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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.

02-27-2018 01:33 - edited 02-27-2018 01:35
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

02-27-2018 01:33 - edited 02-27-2018 01:35
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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

