如何使用R从dropbox下载文件(任何形式)

时间:2023-02-06 07:33:36

I tried

download.file('https://www.dropbox.com/s/r3asyvybozbizrm/Himalayas.jpg',
              destfile="1.jpg",
              method="auto")

but it returns the HTML source of that page.

但它返回该页面的HTML源代码。

Also tried a little bit of rdrop

还试了一下rdrop

library(rdrop2)
# please put in your key/secret
drop_auth(new_usesr = FALSE, key=key, secret=secret, cache=T)

And the pop up website reports:

弹出网站报道:

Invalid redirect_uri: "http://localhost:1410": It must exactly match one of the redirect URIs you've pre-configured for your app (including the path).

I don't understand the URI thing very well. Can somebody recommend some document to read please....

我不太了解URI的事情。有人可以推荐一些文件来阅读....

I read some posts but most of them discuss how to read data from excel files.

我读了一些帖子,但大多数都讨论了如何从excel文件中读取数据。

repmis worked only for reading excel files...

repmis仅用于阅读excel文件...

library(repmis)
repmis::source_DropboxData("test.csv",
                           "tcppj30pkluf5ko",
                           sep = ",",
                           header = F)

Also tried

library(RCurl)
url='https://www.dropbox.com/s/tcppj30pkluf5ko/test.csv'
x = getURL(url)
read.csv(textConnection(x))

And it didn't work...

它不起作用......

Any help and discussion's appreciated. Thanks!

任何帮助和讨论都表示赞赏。谢谢!

2 个解决方案

#1


8  

The first issue is because the https://www.dropbox.com/s/r3asyvybozbizrm/Himalayas.jpg link points to a preview page, not the file content itself, which is why you get the HTML. You can modify links like this though to point to the file content, as shown here:

第一个问题是因为https://www.dropbox.com/s/r3asyvybozbizrm/Himalayas.jpg链接指向预览页面,而不是文件内容本身,这就是您获取HTML的原因。你可以修改这样的链接虽然指向文件内容,如下所示:

https://www.dropbox.com/help/201

E.g., add a raw=1 URL parameter:

例如,添加raw = 1 URL参数:

https://www.dropbox.com/s/r3asyvybozbizrm/Himalayas.jpg?raw=1

Your downloader will need to follow redirects for that to work though.

您的下载程序需要遵循重定向才能使用。

The second issue is because you're trying to use a OAuth 2 app authorization flow, which requires that all redirect URIs be pre-registered. You can register redirect URIs, in your case it's http://localhost:1410, for Dropbox API apps on the app's page on the App Console:

第二个问题是因为您尝试使用OAuth 2应用程序授权流程,这需要预先注册所有重定向URI。您可以在应用程序控制台的应用程序页面上为Dropbox API应用注册重定向URI(在您的情况下为http:// localhost:1410):

https://www.dropbox.com/developers/apps

For more information on using OAuth, you can refer to the Dropbox API OAuth guide here:

有关使用OAuth的详细信息,请参阅此处的Dropbox API OAuth指南:

https://www.dropbox.com/developers/reference/oauthguide

#2


-1  

I use read.table(url("yourdropboxpubliclink")) for instance I use this link

我使用read.table(url(“yourdropboxpubliclink”)),例如我使用此链接

instead of using https://www.dropbox.com/s/xyo8sy9velpkg5y/foo.txt?dl=0, which is chared link on dropbox I use https://dl.dropboxusercontent.com/u/15634209/histogram/foo.txt

而不是使用https://www.dropbox.com/s/xyo8sy9velpkg5y/foo.txt?dl=0,这是dropbox上的chared链接我使用https://dl.dropboxusercontent.com/u/15634209/histogram/foo 。文本

and non-public link raw=1 will work

和非公共链接raw = 1将起作用

It works fine for me.

这对我来说可以。

#1


8  

The first issue is because the https://www.dropbox.com/s/r3asyvybozbizrm/Himalayas.jpg link points to a preview page, not the file content itself, which is why you get the HTML. You can modify links like this though to point to the file content, as shown here:

第一个问题是因为https://www.dropbox.com/s/r3asyvybozbizrm/Himalayas.jpg链接指向预览页面,而不是文件内容本身,这就是您获取HTML的原因。你可以修改这样的链接虽然指向文件内容,如下所示:

https://www.dropbox.com/help/201

E.g., add a raw=1 URL parameter:

例如,添加raw = 1 URL参数:

https://www.dropbox.com/s/r3asyvybozbizrm/Himalayas.jpg?raw=1

Your downloader will need to follow redirects for that to work though.

您的下载程序需要遵循重定向才能使用。

The second issue is because you're trying to use a OAuth 2 app authorization flow, which requires that all redirect URIs be pre-registered. You can register redirect URIs, in your case it's http://localhost:1410, for Dropbox API apps on the app's page on the App Console:

第二个问题是因为您尝试使用OAuth 2应用程序授权流程,这需要预先注册所有重定向URI。您可以在应用程序控制台的应用程序页面上为Dropbox API应用注册重定向URI(在您的情况下为http:// localhost:1410):

https://www.dropbox.com/developers/apps

For more information on using OAuth, you can refer to the Dropbox API OAuth guide here:

有关使用OAuth的详细信息,请参阅此处的Dropbox API OAuth指南:

https://www.dropbox.com/developers/reference/oauthguide

#2


-1  

I use read.table(url("yourdropboxpubliclink")) for instance I use this link

我使用read.table(url(“yourdropboxpubliclink”)),例如我使用此链接

instead of using https://www.dropbox.com/s/xyo8sy9velpkg5y/foo.txt?dl=0, which is chared link on dropbox I use https://dl.dropboxusercontent.com/u/15634209/histogram/foo.txt

而不是使用https://www.dropbox.com/s/xyo8sy9velpkg5y/foo.txt?dl=0,这是dropbox上的chared链接我使用https://dl.dropboxusercontent.com/u/15634209/histogram/foo 。文本

and non-public link raw=1 will work

和非公共链接raw = 1将起作用

It works fine for me.

这对我来说可以。