YJZ
YJZ

Reputation: 4214

how to download file (any form) from dropbox using R

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.

Also tried a little bit of 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....

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

repmis worked only for reading excel files...

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!

Upvotes: 11

Views: 8041

Answers (2)

NG. Hai Tuan
NG. Hai Tuan

Reputation: 19

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

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

and non-public link raw=1 will work

It works fine for me.

Upvotes: 0

Greg
Greg

Reputation: 16940

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/help/201

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

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:

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

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

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

Upvotes: 15

Related Questions