04-05-2016 19:59
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

04-05-2016 19:59
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Howdy,
I'm trying to get access to my time series data on my Charge HR. The R-script below seems to be working in that the authentication works. Call back URI and authentication URI in the app are set to http://localhost:1410/.
However, after I authenticate I get this error:
Waiting for authentication in browser...
Press Esc/Ctrl + C to abort
Authentication complete.
Error in init_oauth2.0(self$endpoint, self$app, scope = self$params$scope, :
Bad Request (HTTP 400).
Any ideas what could be causing this?
library(httr) # 1. Set up credentials fitbit_endpoint <- oauth_endpoint( request = "https://api.fitbit.com/oauth2/token", authorize = "http://localhost:1410/", access = "https://api.fitbit.com/oauth2/token") myapp <- oauth_app( appname = "data_access", key = "MYUSER", secret = "MYSECRET") # 2. Get OAuth # See dev.fitbit.com/docs/oauth2/#scope scope <- c("activities") #,"activity", "heartrate", "nutrition", "weight") fitbit_token <- oauth2.0_token(fitbit_endpoint, myapp, scope = scope, use_basic_auth = TRUE) # 3. Make API requests resp <- GET(url = "GET /1/user/[username]/activities/tracker/date/2016-01-01/today.json", config(token = fitbit_token)) content(resp)
04-09-2016 17:36
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

04-09-2016 17:36
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Any one?

04-09-2016 20:34
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

04-09-2016 20:34
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I got a little bit further on my path by passing some endpoint_parameters to the oauth2.0token
fitbit_endpoint <- oauth_endpoint( request = "https://api.fitbit.com/oauth2/token", authorize = host, #http://localhost:1410/ access = "https://api.fitbit.com/oauth2/token") myapp <- oauth_app( appname = "data_access", key = client, secret = token) # 2. Get OAuth token scope <- c("activity") # See dev.fitbit.com/docs/oauth2/#scope fitbit_token <- oauth2.0_token(fitbit_endpoint, myapp, scope = scope, use_basic_auth = TRUE, user_params = fitbit_endpoint) # 3. Make API requests resp <- GET(url = "https://api.fitbit.com/1/user/-/activities/date/2016-01-01/2016-04-09.json", config(token = fitbit_token)) content(resp)
Unfortunately, when I do content on 'resp' I get this error:
$errors
$errors[[1]]
$errors[[1]]$errorType
[1] "invalid_client"
$errors[[1]]$message
[1] "Invalid authorization header format. Visit https://dev.fitbit.com/docs/oauth2 for more information on the Fitbit Web API authorization process."

04-17-2016 00:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

04-17-2016 00:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I've also got to this point - did you get any further?

06-21-2016 13:47
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

06-21-2016 13:47
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I'm stuck in this part.
library(httr) library(xml2) library(jsonlite) fitbit_endpoint <- oauth_endpoint( request = "https://api.fitbit.com/oauth2/token", authorize = "http://localhost:1410", access = "https://api.fitbit.com/oauth2/token") myapp <- oauth_app( appname = "app", key = "key", #my consumer key secret = "secret") # 2. Get OAuth token scope <- c("activity") # See dev.fitbit.com/docs/oauth2/#scope fitbit_token <- oauth2.0_token(fitbit_endpoint, myapp, scope = scope, use_basic_auth = TRUE) # 3. Make API requests resp <- GET(url = "https://api.fitbit.com/1/user/-/activities/steps/date/today/1m.json", config(token = fitbit_token)) content(resp)
And I get this:
Waiting for authentication in browser...
Press Esc/Ctrl + C to abort
Authentication complete.
Error in init_oauth2.0(self$endpoint, self$app, scope = self$params$scope, :
Bad Request (HTTP 400).
In addition: Warning message:
In strsplit(rawToChar(raw), "\r?\n") :
input string 1 is invalid in this locale

08-30-2016 01:30
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

08-30-2016 01:30
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
For those that find the same forum postings when looking for a solution to import fitbit data into R, the R-package "fitbitr" (https://github.com/teramonagi/fitbitr) works for me.
One additional hint; when defining your application in the fitbit api, set the oauth2 application type to 'server'.

09-08-2017 14:31
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-08-2017 14:31
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I've tried the teramonagi/fitbitr as well as the Avsecz/fitbitr. Both times I'm getting and error. Can't figure out what's up.
Error in oauth2.0_access_token(endpoint, app, code = code, user_params = user_params, :
Unauthorized (HTTP 401). Failed to get an access token.

12-31-2017 05:42
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

12-31-2017 05:42
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Same here.. used to work beginning of this year, maybe there has been some update somewhere?
Not really helpful, but would love a post here with a solution 🙂

12-31-2017 08:27
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



12-31-2017 08:27
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
@zjuul please try to use this page: https://dev.fitbit.com/apps/oauthinteractivetutorial
See if you will be able to get access token and make requests using curl.

01-01-2018 05:02
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-01-2018 05:02
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
That worked.. but not in my script.. 🙂
Dug a bit deeper, and via this URL - https://github.com/r-lib/httr/issues/482 found that upgrading my libs might get it working.
After doing that AND after creating a new fitbit application (new app name + keys) I got it working.
Thanks all.

