0

I am attempting to access the fitbit API using ROAuth but keep falling at the first hurdle.

Here is my code:

library(ROAuth)

reqURL <- "https://api.fitbit.com/oauth/request_token"
accessURL <- "https://api.fitbit.com/oauth/access_token"
authURL <- "https://www.fitbit.com/oauth/authorize"
cKey <- "xxxxx"
cSecret <- "xxxxx"

credentials <- OAuthFactory$new(consumerKey=cKey,
                            consumerSecret=cSecret,
                            requestURL=reqURL,
                            accessURL=accessURL,
                            authURL=authURL)
credentials$handshake()

Running this gives the following rather cryptic error:

Error in strsplit(response, "&") : non-character argument

Any suggestions, greatly appreciated!

seancarmody
  • 6,182
  • 2
  • 34
  • 31
  • I would do something like `options(error = recover)` and try to evaluate `response` expression in its called environment. – agstudy Jun 02 '13 at 14:40
  • response [1] 6f 61 ... [100] 75 74 ... 64 3d 74 72 75 65 attr(,"Content-Type") charset "application/x-www-form-urlencoded" "UTF-8" – seancarmody Jun 03 '13 at 09:04
  • That's an edited extract of `response`. Not sure what to make of that! – seancarmody Jun 03 '13 at 09:04
  • 1
    You might find it easier to use the OAuth support in httr. – hadley Jun 03 '13 at 12:54
  • I seem to be getting a bit further with `httr`. I've based my code on some of the github demos, but when it tries to authenticate in the browser, the page that comes up says "This page is no longer valid. It looks like you provided an invalid token or someone already used the token you provided. Please return to the site or application which sent you to this page and try again." I've tried resetting the keys to no avail. – seancarmody Jun 05 '13 at 02:53
  • I discovered the problem...I was using ouath2 not oauth1. [This example](http://stackoverflow.com/questions/12212958/oauth-authentification-to-fitbit-using-httr/12218175) sorted me out. – seancarmody Jun 05 '13 at 04:13

1 Answers1

1

Following the suggestion of @hadley rather than solving the ROAuth problem, I have switched to using the httr package instead. The code in this question worked for me.

Community
  • 1
  • 1
seancarmody
  • 6,182
  • 2
  • 34
  • 31