R:google translate API(包';translate&';';&#translateR';)

R:google translate API(包';translate&';';&#translateR';),r,google-translate,translate,R,Google Translate,Translate,我正在尝试使用R-Studio的translate和translateR软件包 我已经创建了“服务器”和“浏览器”API密钥。运行示例时,浏览器API工作正常: 但是,在R-Studio中使用任一API键和任一包(translate/translateR)时,我会收到一条错误消息。使用翻译 > library(translate) > set.key("mykey") > translate('Hello, world!', 'en', 'de') Error in func

我正在尝试使用R-Studio的
translate
translateR
软件包

我已经创建了“服务器”和“浏览器”API密钥。运行示例时,浏览器API工作正常:

但是,在R-Studio中使用任一API键和任一包(
translate
/
translateR
)时,我会收到一条错误消息。使用
翻译

> library(translate)
> set.key("mykey")
> translate('Hello, world!', 'en', 'de')
Error in function (type, msg, asError = TRUE)  : 
  SSL certificate problem: unable to get local issuer certificate

可能是什么问题?谢谢你的帮助

问题似乎与系统有关。它在我更改https代理后工作。

似乎问题与系统有关。在我更改https代理后,它可以工作。

我也遇到了一些问题,并编写了一个小函数从API检索数据:

#' Translate with R
#'
#' Translate Keywords or/and text with the Google Translate API
#' The Functions allows to translate keywords or sentences using the Google Translate API.
#' To use this function you need to get a API-Key for the Google Translate API <https://cloud.google.com/translate/docs/?hl=en>.
#' @param text The keyword/sentence/text you want to translate
#' @param API_Key Your API Key. You get the API Key here: <https://cloud.google.com/translate/docs/?hl=en>
#' @param target The Language target your text translated to. For German 'de'. 
#' @param source The Language your given text/keyword is. For example 'en' - english 
#' translate()
#' @examples
#' \dontrun{
#' translate(text = "R is cool", API_Key = "XXXXXXXXXXX", target = "de", source = "en")
#' }


translate <- function(text,
                      API_Key,
                      target = "de",
                      source = "en") {
  b <- paste0(
    '{
    "q": [
    "',
    text,
    '"
    ],
    "target": "',
    target,
    '",
    "source": "',
    source,
    '",
    "format": "text"
}'
)
  url <-
    paste0("https://translation.googleapis.com/language/translate/v2?key=",
           API_Key)
  x <- httr::POST(url, body = b)
  x <- jsonlite::fromJSON(rawToChar(x$content))
  x <- x$data$translations
  return(x$translatedText[1])
  }
用R进行翻译 #' #'使用Google Translate API翻译关键字或/和文本 #这些函数允许使用谷歌翻译API翻译关键词或句子。 #'要使用此函数,您需要获取Google Translate API的API密钥。 #“@param text要翻译的关键字/句子/文本 #“@param API_为您的API密钥设置密钥。您可以在此处获得API密钥: #“@param target将文本翻译为的语言目标。德语的“de”。 #“@param source给定文本/关键字所使用的语言。例如“en”-英语 #"翻译() #“@示例 #“\dontrun{ #“翻译(text=“R很酷”,API_Key=“xxxxxxxxxx”,target=“de”,source=“en”) #' }
translate我在这方面也遇到了一些问题,并编写了一个小函数从API检索数据:

#' Translate with R
#'
#' Translate Keywords or/and text with the Google Translate API
#' The Functions allows to translate keywords or sentences using the Google Translate API.
#' To use this function you need to get a API-Key for the Google Translate API <https://cloud.google.com/translate/docs/?hl=en>.
#' @param text The keyword/sentence/text you want to translate
#' @param API_Key Your API Key. You get the API Key here: <https://cloud.google.com/translate/docs/?hl=en>
#' @param target The Language target your text translated to. For German 'de'. 
#' @param source The Language your given text/keyword is. For example 'en' - english 
#' translate()
#' @examples
#' \dontrun{
#' translate(text = "R is cool", API_Key = "XXXXXXXXXXX", target = "de", source = "en")
#' }


translate <- function(text,
                      API_Key,
                      target = "de",
                      source = "en") {
  b <- paste0(
    '{
    "q": [
    "',
    text,
    '"
    ],
    "target": "',
    target,
    '",
    "source": "',
    source,
    '",
    "format": "text"
}'
)
  url <-
    paste0("https://translation.googleapis.com/language/translate/v2?key=",
           API_Key)
  x <- httr::POST(url, body = b)
  x <- jsonlite::fromJSON(rawToChar(x$content))
  x <- x$data$translations
  return(x$translatedText[1])
  }
用R进行翻译 #' #'使用Google Translate API翻译关键字或/和文本 #这些函数允许使用谷歌翻译API翻译关键词或句子。 #'要使用此函数,您需要获取Google Translate API的API密钥。 #“@param text要翻译的关键字/句子/文本 #“@param API_为您的API密钥设置密钥。您可以在此处获得API密钥: #“@param target将文本翻译为的语言目标。德语的“de”。 #“@param source给定文本/关键字所使用的语言。例如“en”-英语 #"翻译() #“@示例 #“\dontrun{ #“翻译(text=“R很酷”,API_Key=“xxxxxxxxxx”,target=“de”,source=“en”) #' }
翻译服务器和浏览器API帮不了你,你需要谷歌的翻译API。对不起,你能澄清一下吗?我已经启用了谷歌的翻译API——这就是我最初获得“服务器”和“浏览器”API密钥的方式。据我所知,R包
translate
translateR
应该可以使用这些键。我遗漏了什么?您的API请求是否要求有一个包含账单信息的google帐户?如果没有,那么你得到了错误的API。是的,我确实包含了计费信息。同样,基于浏览器的翻译与我的API密钥配合得很好。问题是R包的功能。服务器和浏览器API帮不了你,你需要谷歌的翻译API。对不起,你能澄清一下吗?我已经启用了谷歌的翻译API——这就是我最初获得“服务器”和“浏览器”API密钥的方式。据我所知,R包
translate
translateR
应该可以使用这些键。我遗漏了什么?您的API请求是否要求有一个包含账单信息的google帐户?如果没有,那么你得到了错误的API。是的,我确实包含了计费信息。同样,基于浏览器的翻译与我的API密钥配合得很好。问题是R包的功能。