Using R and the ROAuth package by Jeff Gentry to try and pull data off of fitbit and the Authentication doesn't seem to work. Code as follows:
apiURL = 'api.fitbit.com/'
credentials = OAuthFactory$new(consumerKey=key,
consumerSecret=secret,
requestURL=tokenURL,
accessURL=accessTokenURL,
authURL=authorizeURL
)
and then I run the handshake:
> credentials$handshake()
To enable the connection, please direct your web browser to:
http://www.fitbit.com/oauth/authorize?oauth_token=036afa88a832bfffc72af485e38c1572
When complete, record the PIN given to you and provide it here:
Complete the authorization and paste in the oauth_verifier token, resulting in a proper looking set of credentials.
Finally I try to get the profile data that I'm after:
rawToChar(credentials$OAuthRequest(paste(apiURL,"1/user/userID/profile.json", sep="", collapse=''), "GET"))
And I get this in response:
[1] "{\"errors\":[{\"errorType\":\"oauth\",\"fieldName\":\"n/a\",\"message\":\"No
Authorization header provided in the request. Each call to Fitbit API should be OAuth
signed\"}]}"
Okay finally solved the issue after some digging and emailing with DTL and Geoff Jentry (thanks so much guys).
In the original ROAuth package the oauthGet function did not use the Authorization .opt for the curl call and also had params that looked like this:
params <- c(params, as.list(auth))
getForm(url, .params = params, curl = curl, .opts = c(list(httpget = TRUE), opts, list(...))))
Fitbit.com Api was a little more particular https://wiki.fitbit.com/display/API/OAuth+Authentication+in+the+Fitbit+API needing " to wrap the values of the oauth_params and I made the following mods:
params <-as.list(auth) #dropping the first item in the list which was an extra "GET"
opts=list(httpheader=c(Authorization=paste("OAuth ", paste(names(auth), '="', auth, '"', sep = "", collapse = ",\n "), sep="", collapse='')))
getForm(url, curl = curl, .opts = c( opts))
It seems that specifying the params and listing the options was causing issues.
Finally the form with correct data was obtained!