Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

dropbox

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!

like image 855
YJZ Avatar asked Aug 12 '15 04:08

YJZ


People also ask

How do I download a form from Dropbox?

Sign in to dropbox.com. Hover over the file or folder you'd like to download. Click “…” (ellipsis). Click Download.

How do I export everything from Dropbox?

Open the Dropbox mobile app. Tap the “⁝” (vertical ellipsis on Android) or “…” (ellipsis on iPhone/iPad) next to the file or folder you'd like to export. Tap Share. Tap Export file.


1 Answers

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

like image 160
Greg Avatar answered Oct 31 '22 16:10

Greg