使用 httr 提出具体要求

making specific request with httr

我该如何向 httr 提出这个请求?

'curl -X POST https://api.dropboxapi.com/2/files/list_folder \
    --header "Authorization: Bearer 21318318usdhsdha9283718 " \
    --header "Content-Type: application/json" \
    --data "{\"path\": \"/today/\",\"recursive\": false,\"include_media_info\": false,\"include_deleted\": false}"'

我曾尝试使用 curlconverter,但在这方面效果不佳。我不确定我将如何实施 --data 参数以及接下来的内容。

这对我有用,对你也有用吗?

httr::POST(
  "https://api.dropboxapi.com/2/files/list_folder",
  add_headers(Authorization = "Bearer <token>"),
  content_type_json(),
  body = "{\"path\": \"/folder\",\"recursive\": false,\"include_media_info\": false,\"include_deleted\": false}",
  encode = "json"
)

如果您想对许多文件夹进行概括:

library("httr")
foobar <- function(x) {
  content(POST(
    "https://api.dropboxapi.com/2/files/list_folder",
    add_headers(Authorization = "Bearer <token>"),
    content_type_json(),
    body = list(path = paste0("/", x), recursive = FALSE, 
                include_media_info = FALSE, include_deleted = FALSE),
    encode = "json"
  ))
}

lapply(c('a', 'b', "c"), foobar)