04-05-2016 19:59
04-05-2016 19:59
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
04-09-2016 17:36
Any one?
Best Answer04-09-2016 20:34
04-09-2016 20:34
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."
Best Answer04-17-2016 00:37
04-17-2016 00:37
I've also got to this point - did you get any further?
Best Answer06-21-2016 13:47
06-21-2016 13:47
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
Best Answer08-30-2016 01:30
08-30-2016 01:30
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'.
Best Answer09-08-2017 14:31
09-08-2017 14:31
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.
Best Answer12-31-2017 05:42
12-31-2017 05:42
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 🙂
Best Answer12-31-2017 08:27
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.
12-31-2017 08:27
@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.
Best Answer01-01-2018 05:02
01-01-2018 05:02
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.
Best Answer