使用 rdrop2 和 drop_auth() 获取 Dropbox API 的刷新令牌
我正在尝试创建一个闪亮的应用程序,它使用包 rdrop2 链接到我的保管箱。
我已成功部署该应用程序,它按计划运行了大约 4 个小时。但是,我需要持久的离线访问。 Dropbox 帮助页面显示我需要“刷新令牌”。
目前,为了获取我正在使用的令牌:
library(rdrop2)
token <- drop_auth() # gets credentials
saveRDS(token, "droptoken.rds") # saves credentials
token<-readRDS("droptoken.rds") # read in credentials
drop_auth(new_user = FALSE,
cache = TRUE,
rdstoken = "droptoken.rds")
ui <- # some UI code
server <- function(input, output,session) {
# some server code
}
shinyApp(ui = ui, server = server)
这将创建一个具有“sl”的令牌。访问令牌(短期),到期时间为 14400,即 4 小时。 4 小时后,该应用程序由于“未经授权的 HTTP 401”错误而不再运行。
有人可以帮助我了解如何调整此代码以获取刷新令牌吗?
注意:dropbox 不再允许无期限的令牌(截至 2021 年 9 月),因此我需要沿着刷新令牌路线进行。
I'm trying to create a shiny app which links to my dropbox using the package rdrop2.
I have successfully managed to deploy the app and it runs as planned for around 4 hours. However, I need long lasting offline access. Dropbox help pages say that I'll need a 'refresh token'.
Currently to get my token I am using:
library(rdrop2)
token <- drop_auth() # gets credentials
saveRDS(token, "droptoken.rds") # saves credentials
token<-readRDS("droptoken.rds") # read in credentials
drop_auth(new_user = FALSE,
cache = TRUE,
rdstoken = "droptoken.rds")
ui <- # some UI code
server <- function(input, output,session) {
# some server code
}
shinyApp(ui = ui, server = server)
This creates a token that has a 'sl.' access token (short lived) which expires_in 14400, which is 4 hours. After 4 hours, the app no longer works due to an 'Unathorised HTTP 401' error.
Could anyone provide me help on how to adapt this code to obtain a refresh token?
NB: dropbox no longer allow tokens with no expiry (as of September 2021) so I need to go down the refresh token route.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道您是否仍然需要帮助,但我最近的任务是在实习计划中解决这个问题,并设法找到解决方案。
目前,rdrop2 的
drop_auth()
函数将生成具有以下凭据的令牌:access_token、token_type、expires_in、uid、account_id
。由于访问令牌现在仅持续 4 小时,因此我们需要刷新令牌作为凭证的一部分,以便我们可以在每次过期时获得新的访问令牌。要生成带有刷新令牌的令牌对象,我们需要修改 drop_auth() 函数内的授权端点。这看起来像这样:
这将生成一个带有这些凭证的令牌:
; access_token、token_type、expires_in、refresh_token、uid、account_id
。新令牌现在将具有刷新令牌,HTTP API 可使用该刷新令牌自动刷新访问令牌。调用 rdrop2 函数时指定新令牌非常重要,否则它将无法工作。示例:
希望这有帮助!
I don't know if you still need help but I was recently tasked to address this issue in my internship program and managed to find a solution.
Currently, rdrop2's
drop_auth()
function will generate a token with these credentials:<credentials> access_token, token_type, expires_in, uid, account_id
. Since access tokens last only 4 hours now, we will need a refresh token as a part of our credentials so that we may get a new access token every time it expires.To generate a token object with a refresh token, we will need to modify the authorization endpoint inside the
drop_auth()
function. This will look something like this:This will generate a token with these credentials:
<credentials> access_token, token_type, expires_in, refresh_token, uid, account_id
. The new token will now have a refresh token that the HTTP API can use to automatically refresh the access token.It is very important that you specify the new token when calling rdrop2 functions, otherwise it will not work. Example:
Hope this helps!