使用Jeff Gentry的R和ROAuth软件包尝试从fitbit中提取数据,并且身份验证似乎不起作用。代码如下:
apiURL = 'api.fitbit.com/'
credentials = OAuthFactory$new(consumerKey=key,
consumerSecret=secret,
requestURL=tokenURL,
accessURL=accessTokenURL,
authURL=authorizeURL
)
然后我进行握手:
> 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:
完成授权并粘贴oauth_verifier token ,从而获得一组看起来正确的凭据。
最后,我尝试获取所需的配置文件数据:
rawToChar(credentials$OAuthRequest(paste(apiURL,"1/user/userID/profile.json", sep="", collapse=''), "GET"))
我得到这个回应:
[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在与DTL和Geoff Jentry进行了一些挖掘和发送电子邮件之后(终于感谢了很多家伙),终于解决了这个问题。
在原始的ROAuth包中,oauthGet函数未使用curl调用Authorization .opt,并且还具有如下所示的参数:
params <- c(params, as.list(auth))
getForm(url, .params = params, curl = curl, .opts = c(list(httpget = TRUE), opts, list(...))))
Fitbit.com Api更加特殊https://wiki.fitbit.com/display/API/OAuth+Authentication+in+the+Fitbit+API,需要“来包装oauth_params的值,我制作了以下mod:
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))
似乎指定参数并列出选项会引起问题。
最终获得了具有正确数据的表格!
关于r - ROAuth R和FitBit API错误:未提供授权 header ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11587881/