OAuth2使用httr与R进行身份验证
我正在尝试从Polar Accesslink API读取一些数据。我已经阅读了Oauth2.0的文档和示例(我不太熟悉Python)以及httr示例/演示: 这是我的密码:OAuth2使用httr与R进行身份验证,r,oauth-2.0,httr,R,Oauth 2.0,Httr,我正在尝试从Polar Accesslink API读取一些数据。我已经阅读了Oauth2.0的文档和示例(我不太熟悉Python)以及httr示例/演示: 这是我的密码: library(httr) client_id <- rstudioapi::askForPassword() client_secret <- rstudioapi::askForPassword() # redirect_uri determined in registration to http:
library(httr)
client_id <- rstudioapi::askForPassword()
client_secret <- rstudioapi::askForPassword()
# redirect_uri determined in registration to http://localhost:1410/
app <- oauth_app(appname = "polar_app",
key = client_id,
secret = client_secret)
endpoint <- oauth_endpoint(
request = NULL,
authorize = "https://flow.polar.com/oauth2/authorization",
access = "https://polarremote.com/v2/oauth2/token")
token <- oauth2.0_token(endpoint = endpoint,
app = app,
scope = "accesslink.read_all", # tested also without scope
use_basic_auth = T # tested both T and F
)
它以url localhost:1410/?state={state}&code={code}打开浏览器,并显示:
“身份验证已完成。请关闭此页并返回R。”
基于API文档和github Python示例,我无法确定是否需要在oauth2.0令牌中为用户参数或查询额外授权设置一些值。存在同样的问题。向支持部门发送了一条消息,他们回来时确保您包含标题“Content Type:application/x-www-form-urlencoded”,并且正文以纯文本/原始文本形式发送,并包含“grant\u Type=authorization\u code&code=”
我没有对此进行测试,但如果您还没有找到解决相同问题的方法,希望它能帮助您解决问题。向支持部门发送了一条消息,他们回来时确保您包含标题“Content Type:application/x-www-form-urlencoded”,并且正文以纯文本/原始文本形式发送,并包含“grant\u Type=authorization\u code&code=” 我还没有测试过,但如果你还没有找到解决方案,希望它能帮助你
Waiting for authentication in browser...
Press Esc/Ctrl + C to abort
Authentication complete.
Error in oauth2.0_access_token(endpoint, app, code = code, user_params = user_params, :
Bad Request (HTTP 400). Failed to get an access token.