rDrop Dropbox API非到期令牌/无缝令牌问题 [英] rDrop dropbox api non-expiring tokens/seamless token issues

查看:103
本文介绍了rDrop Dropbox API非到期令牌/无缝令牌问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 rDrop 包,该包可从 https获得://github.com/karthikram/rDrop ,并进行了一些调整(由于所有功能都无法正常运行,正如您一直期望的那样),我终于以我的方式使其工作了想要,但是每次您获得令牌后仍需要授权验证,以允许使用该应用程序,因为我认为令牌会随着时间而过期...(如果不是这种情况,我可以在自己的代码中进行硬编码令牌,请告诉我,因为这也将是一个很好的解决方案...)

I am using the rDrop package that is available from https://github.com/karthikram/rDrop, and after a bit of tweaking (as all the functions don't quite work as you would always expect them to) I have got it to work finally in the way I would like, but it still requires authorisation verification to allow the use of the app, once you get the token each time, as I think that tokens expire over time...(if this is not the case and I can hard code in my token please tell me as that would be a good solution too...)

基本上,我希望通过一种几乎无缝的方式从命令行中的Dropbox文件夹中下载csv文件在一行代码中使用R,这样我就不需要在令牌请求后单击允许按钮。

Basically I wanted a near seamless way of downloading csv files from my dropbox folders from the commandline in R in one line of code so that I dont need to click on the allow button after the token request.

这可能吗?

这是我用来包装Dropbox CSV下载的代码。

Here is the code I used to wrap up a dropbox csv download.

db.csv.download <- function(dropbox.path, ...){

cKey <- getOption('DropboxKey')
cSecret <- getOption('DropboxSecret')
reqURL <- "https://api.dropbox.com/1/oauth/request_token"
authURL <- "https://www.dropbox.com/1/oauth/authorize"
accessURL <- "https://api.dropbox.com/1/oauth/access_token/"

require(devtools)
install_github("ROAuth", "ropensci")
install_github("rDrop", "karthikram")
require(rDrop)
dropbox_oa <- oauth(cKey, cSecret, reqURL, authURL, accessURL, obj = new("DropboxCredentials"))
cred <- handshake(dropbox_oa, post = TRUE)
raw.data <- dropbox_get(cred,dropbox.path)
data <- read.csv(textConnection(raw.data), ...)
data
}

哦,如果不是很明显,我将我的保管箱密钥和秘密放在.R中配置文件,这是getOption部分所指的。

Oh and if its not obvious I have put my dropbox key and secret in my .Rprofile file, which is what the getOption part is referring to.

在此先感谢您提供的任何帮助。 (要获得加分,如果有人知道如何摆脱所有加载消息,即使是很好的安装……)

Thanks in advance for any help that is provided. (For bonus points...if anybody knows how to get rid of all the loading messages even for the install that would be great...)

推荐答案

library(rDrop) 
# my keys are in my .rprofile, otherwise specifiy inline
db_token <- dropbox_auth()
# Hit ok to authorize once through the browser and hit enter back at the R prompt.
save(db_token, file="my_dropbox_token.rdata")

Dropbox令牌不是过期,可以随时从 Dropbox网站面板撤消。

Dropbox token are non-expiring and can be revoked anytime from the Dropbox web panel.

供将来使用:

library(rDrop)
load('~/Desktop/my_dropbox_token.rdata')
df <- data.frame(x=1:10, y=rnorm(10))
> df
    x          y
1   1 -0.6135835
2   2  0.3624928
3   3  0.5138807
4   4 -0.2824156
5   5  0.9230591
6   6  0.6759700
7   7 -1.9744624
8   8 -1.2061920
9   9  0.9481213
10 10 -0.5997218
dropbox_save(db_token, list(df), file="foo", ext=".rda")
rm(df)
df2 <- db.read.csv(db_token, file='foo.rda')
> df2
    x          y
1   1 -0.6135835
2   2  0.3624928
3   3  0.5138807
4   4 -0.2824156
5   5  0.9230591
6   6  0.6759700
7   7 -1.9744624
8   8 -1.2061920
9   9  0.9481213
10 10 -0.5997218

如果您还有其他问题,请提交问题

If you have additional problems, please file an issue.

这篇关于rDrop Dropbox API非到期令牌/无缝令牌问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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