我正在尝试从Polar Accesslink API中读取一些数据。我已经阅读了文档和示例(我对Python不是特别熟悉),以及Oauth2.0的httr示例/演示:
代码的最后一部分(token)产生了以下错误:
它会打开一个浏览器,访问URL localhost:1410/?state={STATE}&code={CODE},并显示以下内容:“认证完成,请关闭此页面并返回R。”根据API文档和Github Python示例,我无法确定是否需要在oauth2.0_token中设置user_params或query_authorize_extra的某些值。
https://www.polar.com/accesslink-api/#polar-accesslink-api
https://github.com/polarofficial/accesslink-example-python
这是我的代码:
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
)
代码的最后一部分(token)产生了以下错误:
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.
它会打开一个浏览器,访问URL localhost:1410/?state={STATE}&code={CODE},并显示以下内容:“认证完成,请关闭此页面并返回R。”根据API文档和Github Python示例,我无法确定是否需要在oauth2.0_token中设置user_params或query_authorize_extra的某些值。