2016-07-15 6 views
0

translatetranslateRパッケージをR-Studioで使用しようとしています。R:google translate API(パッケージ '翻訳'& '' translateR ')

「サーバー」と「ブラウザ」APIキーの両方を作成しました。例を実行するときに、ブラウザのAPIが正常に動作します:しかし

https://www.googleapis.com/language/translate/v2?key=YOUR_API_KEY&q=hello%20world&source=en&target=de

、APIキーとR-Studioの(translate/translateR)とのいずれかのパッケージのいずれかを使用しているとき、私はエラーメッセージを得ます。 With

> 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 

何が問題なのですか?手伝ってくれてありがとう!

+0

サーバーとブラウザAPIのお手伝いをしていないだろう、あなたはGoogleの翻訳APIが必要です。 https://cloud.google.com/translate/docs/ –

+0

申し訳ありませんが、明確にできますか?私は既にGoogleの翻訳APIを有効にしています。つまり、元々は「サーバー」と「ブラウザ」のAPIキーを取得しています。 Rパッケージ 'translate'と' translateR'は、これらのキーを使って私の理解した作業にすべきです。私は何が欠けていますか? –

+0

APIリクエストで請求情報が記載されたGoogleアカウントを作成する必要がありますか?そうでない場合は、間違ったAPIを取得します。 –

答えて

1

問題はシステムに関連しているようです。私はhttpsプロキシを変更した後に動作します。

0

また、私はこれでいくつかの問題を抱えていたし、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]) 
    } 

はここに要点を更新:https://gist.github.com/dschmeh/8414b63c3ab816c44995cd6872165f0e