小编Yan*_*ham的帖子

Oauth使用httr对Fitbit进行身份验证

我正在尝试使用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
)
Run Code Online (Sandbox Code Playgroud)

我完成了身份验证.来自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>'"}]} 
Run Code Online (Sandbox Code Playgroud)

关于问题可能是什么的任何线索?

r oauth fitbit httr

5
推荐指数
1
解决办法
2683
查看次数

标签 统计

fitbit ×1

httr ×1

oauth ×1

r ×1