使用httr对Fitbit进行Oauth身份验证 [英] Oauth authentification to Fitbit using httr

查看:123
本文介绍了使用httr对Fitbit进行Oauth身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 httr库连接到fitbit api.

I'm trying to connect to the fitbit api using the httr library.

使用提供的示例,我想出了以下代码:

Using the examples provided, I came up with the following code:

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则会引发错误消息

I get the Authentication complete. message from httr, but trying to access the api then throws an error message

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

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

Any clue about what the problem might be?

推荐答案

问题来自httr库,该库使用curlEscape编码参数,而OAuth 1.0规范则需要百分比编码(请参见

The problem comes from the httr library, that uses curlEscape for encoding paramaters while the OAuth 1.0 specifications requires percent encoding (see this page).

使用curlPercentEncode替换对curlEscape的调用即可解决此问题!

Replacing calls to curlEscape with curlPercentEncode solves the issue!

非常感谢@ mark-s的帮助.

many thanks to @mark-s for his help.

这篇关于使用httr对Fitbit进行Oauth身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆