Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ROAuth R和FitBit API错误:未提供授权标头_R_Oauth_Fitbit - Fatal编程技术网

ROAuth R和FitBit API错误:未提供授权标头

ROAuth R和FitBit API错误:未提供授权标头,r,oauth,fitbit,R,Oauth,Fitbit,使用Jeff Gentry的R和ROAuth包尝试从fitbit中提取数据,验证似乎不起作用。代码如下: apiURL = 'api.fitbit.com/' credentials = OAuthFactory$new(consumerKey=key, consumerSecret=secret, requestURL=tokenURL,

使用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_验证器令牌中,生成一组外观正确的凭据

最后,我尝试获取我要查找的配置文件数据:

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\"}]}"

如果您还没有,请确保您拥有CRAN上没有的最新版本(0.9.2):

如果您使用的是Windows,则需要使用此窗口:

还有其他人正在研究该软件包的未来开发,我原以为他们已经有了一个新版本,但显然没有,我可能应该向CRAN提交0.9.2,以防它继续需要一段时间


如果这不起作用,那可能是Fitbit所特有的。我已经看到一些网站不发挥良好的w/ROAuth。如果0.9.2仍然失败,请告诉我,我将尝试查看。

好的,在与DTL和Geoff Jentry进行了一些挖掘和电子邮件发送后,终于解决了这个问题(非常感谢大家)

在原始ROAuth包中,oauthGet函数没有使用授权。选择curl调用,并且还有如下参数:

params <- c(params, as.list(auth))
getForm(url, .params = params, curl = curl, .opts = c(list(httpget = TRUE),  opts,  list(...))))

params仍然无法让它正确发送授权头(我认为这就是问题所在)。在oauthGET函数的某个地方,必须设置一些附加的.opts,但我不知道是哪一个。写信给RCurl的作者Duncan Lang,看看他是否知道.DTL实际上是接管ROAuth的人之一,所以你可能会问他关于版本0.99.2(他当前的devel版本)的另一种可能性。好吧,取得一些进展,对于fitbit来说,看起来你需要在将Oauth参数作为值传递之前将其用引号括起来。现在为RCurl打开verbose=T选项并获得更多有用的信息
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))