if (!require("httr")) {
install.packages("httr", repos="http://cran.rstudio.com/")
library("httr")
}
if (!require("jsonlite")) {
install.packages("jsonlite", repos="http://cran.rstudio.com/")
library("jsonlite")
}
我的 Get 工作正常...
api <- "xxxxxxxxxxxxxxxx"
url <-paste0(
"https://translation.googleapis.com/language/translate/v2/languages/?
key=",api
)
data3 <- GET(url)
data3 <- content(data3)
data3 <- as.data.frame(data3)
data3 <- as.data.frame(t(data3))
我的 POST 不起作用
url <- paste0(
"https://translation.googleapis.com/language/translate/v2/detect/?key=",api
)
request_body <- data.frame(message = "hello")
request_body_json <- toJSON(list(documents = request_body), auto_unbox = TRUE)
result <- POST(url, body = request_body_json)
我试图让语言检测工作我的理解是我们需要在 JSON 文件中发布到谷歌 API 但是我收到错误 #"code": 400, #"message": "Required Text"
我希望有人能指出我正确的方向我知道有一个 R 包但我正在尝试学习如何在没有包的情况下做到这一点,因为有时谷歌或微软会更新他们的 API 并且 # 包没有得到更新(示例:自 API 更新以来,TranslateR 不支持 Microsoft,因此我想尽可能多地学习如何手动执行此操作 # https://cloud.google.com/translate/docs/quickstart?csw=1 https: //translation.googleapis.com/ $discovery/rest?version=v2