使用api访问路径名中包含空格的Dropbox文件

时间:2013-01-31 00:41:19

标签: r dropbox-api httr

此问题与我之前的问题reading raw data in R to be saved as .RData file using the dropbox api

有关

当我的路径包含非网址标准字符

时,我遇到了问题

上一个问题中的db.file.name只是dropbox中相关文件的路径。

但是路径中有一个空格以及感叹号。我有一种感觉,这些需要转换为相关的格式,以便GET请求可以工作...但不太确定转换是什么....

所以使用并继续我之前的例子...

require(httr)
require(RCurl)
db.file.name <- "!! TEST FOLDER/test.RData"
db.app <- oauth_app("db",key="xxxxx", secret="xxxxxxx")
db.sig <- sign_oauth1.0(db.app, token="xxxxxxx", token_secret="xxxxxx")

response <- GET(url=paste0("https://api-content.dropbox.com/1/files/dropbox/",curlEscape(db.file.name)),config=c(db.sig,add_headers(Accept="x-dropbox-metadata")))

响应是一个错误,没有文件被下载...使用文档页面https://www.dropbox.com/developers/reference/api它建议将URL放入UTF-8编码...我不知道如何做/不确定它是否有效。

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:1)

我之前很接近......我只需要使用gsub重新插入斜杠,以便GET请求正常工作......所以结果是

response <- GET(url=paste0("https://api-content.dropbox.com/1/files/dropbox/",gsub("%2F","/",curlEscape(db.file.name))),config=c(db.sig,add_headers(Accept="x-dropbox-metadata")))

答案 1 :(得分:0)

来自?iconv的快速复制粘贴,

x <- "fa\xE7ile"
Encoding(x) <- "latin1"
charToRaw(xx <- iconv(x, "latin1", "UTF-8"))
[1] 68 74 74 70 3a 2f 2f 73 74 61 63 6b 6f 76 65 72 66 6c 6f 77 2e 63 6f 6d
Encoding(x)
[1] "latin1"
Encoding(xx)
[1] "UTF-8"

这会回答你的问题吗?