Oauth Fitbit authentication using httr

I am trying to connect to apythit api using httr library .

Using the above examples, I came up with the following code:

library(httr)

key <- '<edited>'
secret <- '<edited>'
tokenURL <- 'http://api.fitbit.com/oauth/request_token'
accessTokenURL <- 'http://api.fitbit.com/oauth/access_token'
authorizeURL <- 'https://www.fitbit.com/oauth/authorize'

fbr <- oauth_app('fitbitR',key,secret)
fitbit <- oauth_endpoint(tokenURL,authorizeURL,accessTokenURL)

token <- oauth1.0_token(fitbit,fbr)
sig <- sign_oauth1.0(fbr,
    token=token$oauth_token,
    token_secret=token$oauth_token_secret
)

I will complete authentication. message from httr, but trying to access the api then gives an error message

GET("http://api.fitbit.com/1/user/-/activities/date/2012-08-29.json", sig)
Response [http://api.fitbit.com/1/user/-/activities/date/2012-08-29.json]
  Status: 401
  Content-type: application/x-www-form-urlencoded;charset=UTF-8
{"errors":[{"errorType":"oauth","fieldName":"oauth_access_token","message":"Invalid signature or token '<edited>' or token '<edited>'"}]} 

Is there any clue on what might be the problem?

+5
source share
2 answers

The problem arises from the httr library, which uses curlEscape to encode parameters, while the OAuth 1.0 specifications require percent encoding (see this page ).

Replacing curlEscape calls with curlPercentEncode solves the problem!

many thanks @ mark-s for the help.

+4
source

, , , httr. httr:

sig <- sign_oauth1.0(myapp, token$oauth_token, token$oauth_token_secret)

:

sig <- sign_oauth1.0(fbr,
    token=token$oauth_token,
    token_secret=token$oauth_token_secret
)

" =" "token_secret =" ?

+2

All Articles