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

编程入门 行业动态 更新时间:2024-10-26 20:34:06
本文介绍了使用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 <- 'api.fitbit/oauth/request_token' accessTokenURL <- 'api.fitbit/oauth/access_token' authorizeURL <- 'www.fitbit/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("api.fitbit/1/user/-/activities/date/2012-08-29.json", sig) Response [api.fitbit/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身份验证

本文发布于:2023-10-10 12:08:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1478628.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:身份验证   httr   Fitbit   Oauth

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!