Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Working R script Using API? [R] [Mac OS X]

ANSWERED

Hey all - does anyone have a working R script to access the API?

 

Everything I've got and research I've done to authenticate via oauth 1 or 2 seems broken using the httr package.

 

For oauth 2:

 

library(httr)
app = '<OAuth 2.0 Client ID>'
key <- '<Client (Consumer) Key>'
secret <- '<Client (Consumer) Secret>'
accessTokenURL <- 'https://api.fitbit.com/oauth2/token'
authorizeURL <- 'https://www.fitbit.com/oauth2/authorize'

fbr <- oauth_app(key,app,NULL)
fitbit <- oauth_endpoint(NULL, authorizeURL,accessTokenURL)
token <- oauth2.0_token(fitbit,fbr,scope='profile',as_header=TRUE, cache=FALSE)

 

When I check token$credentials I get the error message:

$errors
$errors[[1]]
$errors[[1]]$errorType
[1] "oauth"

$errors[[1]]$fieldName
[1] "n/a"

$errors[[1]]$message
[1] "No Authorization header provided in the request. Each call to Fitbit API should be OAuth signed"



$success
[1] FALSE

 

I have tried all the misc settings in fitbit setting up my app, both as a server and a client, and I have my callback URL correctly set up as http://localhost:1410

 

I'm running in R Studio version 0.98.1102 and R 

 

Any ideas?

 

Thanks,

Isaac

 

Current session info:

R version 3.1.2 (2014-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] httr_1.0.0

loaded via a namespace (and not attached):
[1] curl_0.9.3      httpuv_1.3.2    jsonlite_0.9.14 R6_2.0.1        Rcpp_0.11.4     stringr_0.6.2  
[7] tools_3.1.2    
Best Answer
0 Votes
25 REPLIES 25

So I have http://localhost:1410 in the callback URI

 

Here are my app settings:

 

OAuth 2.0 Client ID
SECRET FOOL
Client (Consumer) Secret
SECRET FOOL
OAuth 2.0: Authorization URI
https://www.fitbit.com/oauth2/authorize
OAuth 2.0: Access/Refresh Token Request URI
https://api.fitbit.com/oauth2/token
 
Application name: data_access
Application Website: http://localhost:1410/
Organization: website.io
Browser/Personal
CallBackURI: http://localhost:1410/
 
READ ONLY
 
Do any of these settings look askew?
 
Best Answer
0 Votes
I feel like I'm missing something obvious here that is totally not obvious to me. I'm just running the script as is but substituting in my client ID and secret. Am I supposed to be doing anything with the implicit authorization, which looks like a long as URL with params in it? (https://community.fitbit.com/t5/Web-API/redirect-uri/td-p/998628)
Best Answer
0 Votes

Change your Callback URL in your Application Setttings from

http://localhost:1410/

to

http://localhost:1410

Best Answer
0 Votes

BOOM!

That did it. That brought me to a grant authorization page!

 

Now I get this error

$errors
$errors[[1]]
$errors[[1]]$errorType
[1] "validation"

$errors[[1]]$fieldName
[1] "resource path"

$errors[[1]]$message
[1] "Invalid time series resource path: /activities/activity"

 

I think I can figure out how to sort through this by going through the API docs again

Best Answer
0 Votes

After a break of a couple of months I ran the same scripts again (that were working before) and got the error:

 

The app you're trying to connect did not provide valid information to Fitbit. Please report this issue to them.

Developer information: invalid_request - Invalid redirect_uri parameter value

 
To get it working again I changed the Callback URL in Application Setttings from

 

http://localhost:1410

to

http://localhost:1410/

 

I'm not sure if my update to httr 1.1 (dev version downloaded today) made any difference. Just mentioning in case anyone runs into the same issue.

 
Best Answer

I get the following errors

"Error in structure(list(method = method, url = url, headers = keep_last(headers),  :
  object 'token' not found"

 

"Error in as.request(config) : object 'gtoken' not found"

Best Answer
0 Votes