Fitbit Java Https support

1k views Asked by At

Does Fitbit for Java actually support https yet?

Previously, the code worked. Now the code returns an error requesting that I use HTTPS.

{"errors":[{"errorType":"request","fieldName":"n/a","message":"This request should use https protocol."}],"success":false}

at com.fitbit.api.client.FitbitApiClientAgent.getUserInfo(FitbitApiClientAgent.java:2063)
at com.fitbit.api.client.FitbitApiClientAgent.getUserInfo(FitbitApiClientAgent.java:2039)
at Auth.populateDataGetters(Auth.java:112)
at Auth.<init>(Auth.java:106)
at Driver.main(Driver.java:18)
Caused by: com.fitbit.api.FitbitAPIException: 400: The request was invalid. An accompanying error message will explain why.

As far as I know, OAuth seems to work fine.

The only URL I have in my code that isn't https is:

String API_BASE_URL         = "api.fitbit.com";

When I change this string to "https://api.fitbit.com", I get the error

Caused by: com.fitbit.api.FitbitAPIException: https
at com.fitbit.api.client.http.HttpClient.httpRequest(HttpClient.java:473)
at com.fitbit.api.client.http.HttpClient.get(HttpClient.java:398)
at com.fitbit.api.client.FitbitApiClientAgent.httpGet(FitbitApiClientAgent.java:2784)
at com.fitbit.api.client.FitbitApiClientAgent.httpGet(FitbitApiClientAgent.java:2734)
at com.fitbit.api.client.FitbitApiClientAgent.getUserInfo(FitbitApiClientAgent.java:2059)
... 4 more
Caused by: java.net.UnknownHostException: https
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:211)
at sun.net.www.http.HttpClient.New(HttpClient.java:308)
at sun.net.www.http.HttpClient.New(HttpClient.java:326)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:996)

The stable Java Fitbit library has not been updated in 2 years and the Java example code isn't very helpful for a standalone application.

2

There are 2 answers

0
pierego On

Well. I went on the fitbit dev forums, and it seems the API posted on the main website (1.0.25) is depreciated and will not work with https.

Essentially you need to recompile the source.

Someone also recompiled the source and posted it in the forums. Be wary obviously.

Also leave the base url as "api.fitbit.com".

0
deadcyclo On

I've forked the project here: https://github.com/deadcyclo/fitbit4j

And published a public maven repository here: https://nexus.vanntett.net/content/repositories/fitbit/

Feel free to use it.

Currently only available version is 1.0.26 (since it's the only working version).

I'll keep the fork and repository in sync if fitbit ever decides to update the project.

Edit: Changed to HTTPS