10-19-2016 08:57 - edited 10-19-2016 08:57
10-19-2016 08:57 - edited 10-19-2016 08:57
Using the following R code to get my token:
library(httr) appname = "HeartRate" key = "2282KN" secret = "31d.........................607" request = "https://api.fitbit.com/oauth2/token" authorize ="http://localhost:1410" access = "https://api.fitbit.com/oauth2/token" endpoint <- httr::oauth_endpoint(request, authorize, access) myapp <- httr::oauth_app("r-package", key, secret) scope <- c("sleep", "activity", "heartrate", "location", "nutrition", "profile", "settings", "social", "weight") # 2. Get OAuth token fitbit_token <- oauth2.0_token(endpoint, myapp, scope = scope, use_basic_auth = TRUE, user_params = endpoint) # 3. Make API requests resp <- GET(url="https://api.fitbit.com/1/user/-/activities/heart/date/today/1d.json") content(resp)
I seem to get the token just fine:
Authentication complete. Please close this page and return to R.
I make the GET request but the response is an error 401
invalid_client" $errors[[1]]$message [1] "Invalid authorization header format.
The Response contains:
I know its a problem with headers but I don't know how to change the code to make it work. Can anyone see whats wrong with the code.
Thanks
10-19-2016 10:07
10-19-2016 10:07
@Eoghan Are you attempting to get Intraday data from someone other than the owner of the app? If you don't have access to Intraday Time Series, then only the owner of the app can pull their own Intraday data using a 'Personal' app.
10-20-2016 03:18 - edited 10-20-2016 03:28
10-20-2016 03:18 - edited 10-20-2016 03:28
Andrew,
I am trying to access my own app called HeartRate which is set to 'personal', using my own client Id and secret.
When I call:
fitbit_token <- oauth2.0_token(endpoint, myapp, scope = scope, use_basic_auth = TRUE, user_params = endpoint)
my browser pops up saying authentication complete. Notice the URL.
http://localhost:1410/?client_id=2282KN&scope=sleep%20activity%20heartrate%20location%20nutrition%20profile%20settings%20social%20weight&redirect_uri=http%3A%2F%2Flocalhost%3A1410%2F&response_type=code&state=KQmkk0aylo
but I dont get to the normal fitbit authorization form seen below:
is this beacuse I use:
authorize ="http://localhost:1410"
instead of
authorize = "http://www.fitbit.com/oauth/authorize"
which I see in many examples around the web, but doesn't seem to work either.
The only request I try is:
GET(url="https://api.fitbit.com/1/user/-/activities/heart/date/today/1d.json")
which is'nt Intraday is it?
Any help appreciated. Im so close to geting it working.
10-20-2016
03:34
- last edited on
10-20-2016
11:20
by
AndrewFitbit
10-20-2016
03:34
- last edited on
10-20-2016
11:20
by
AndrewFitbit
I changed my code to this
authorize = "http://www.fitbit.com/oauth/authorize"
now I get a used token message
Moderator edit: personal info removed
10-20-2016 11:19
10-20-2016 11:19