【问题标题】:accessing dropbox files with spaces in path name using the api使用 api 访问路径名中带有空格的 Dropbox 文件
【发布时间】:2013-01-31 18:19:19
【问题描述】:

这个问题和我之前的问题reading raw data in R to be saved as .RData file using the dropbox api有关

当我的路径包含非 url 标准字符时遇到问题

上一个问题中的 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 编码...我不知道该怎么做/不确定它有效。

任何帮助将不胜感激。

【问题讨论】:

    标签: r dropbox-api httr


    【解决方案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")))
    

    【讨论】:

    • 谢谢!即使我没有使用过这个答案,但curlEscape 是我需要的。
    【解决方案2】:

    来自?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"
    

    这能回答你的问题吗?

    【讨论】:

    • 不幸的是,这并没有帮助。谢谢你的尝试。我已经意识到这与感叹号的编码有关,因为文件路径中的空格使用函数URLencode 转换为%20,即我尝试不使用感叹号,它可以工作,但一旦添加感叹号...不再...
    猜你喜欢
    • 1970-01-01
    • 2011-07-18
    • 2014-09-07
    • 1970-01-01
    • 2012-02-26
    • 1970-01-01
    • 1970-01-01
    • 2021-08-26
    • 2020-03-27
    相关资源
    最近更新 更多