【发布时间】:2012-07-20 05:36:41
【问题描述】:
使用 R 和 Jeff Gentry 的 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 令牌中,从而生成一组外观正确的凭据。
最后我尝试获取我所追求的个人资料数据:
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\"}]}"
【问题讨论】: