我正在尝试使用httr文库连接到fitbit api。
使用所提供的示例,我得出了以下代码:
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
)我完成了认证。来自httr的消息,但试图访问api则引发一条错误消息。
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>'"}]} 知道问题出在哪里吗?
发布于 2012-09-03 09:00:06
问题来自httr库,它使用curlEscape编码参数,而OAuth 1.0规范需要百分比编码(参见此页)。
用curlEscape替换对curlPercentEncode的调用解决了这个问题!
非常感谢马克对他的帮助。
发布于 2012-08-31 15:14:52
我注意到的唯一一点是,您获得签名的调用与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=“和"token_secret=”吗?
https://stackoverflow.com/questions/12212958
复制相似问题