簡體   English   中英

谷歌翻譯API認證【郵遞員】

[英]Google Translate API authentication [postman]

我遇到了 Google Translate API 的問題(和我之前的一樣多......)。 我需要通過 Postman 運行測試查詢以獲得簡單的字符串翻譯。 沒有什么太花哨的。

我正在嘗試根據文檔構建請求,但顯然我目前失敗了。

使用 API 密鑰時,Google 說我應該直接將key=MY_KEY添加到請求字符串中。

這是一個類似的問題: 為什么 Google Translate API 不接受 JSON 請求正文中的 API-Key? 但是沒有人提供一個很好的答案(我也遇到了不同的錯誤)

我當前的示例如下所示:

POST
https://translation.googleapis.com/language/translate/v2
?q=The Great Pyramid of Giza (also known as the Pyramid of Khufu or the Pyramid of Cheops) is the oldest and largest of the three pyramids in the Giza pyramid complex.
&source="en"
&target="es"
&format="text"
&key=MY_KEY_STRING

不幸的是,我得到了一個 400: Invalid Value

{
"error": {
    "code": 400,
    "message": "Invalid Value",
    "errors": [
        {
            "message": "Invalid Value",
            "domain": "global",
            "reason": "invalid"
        }
    ]
}

也許有人知道問題是什么? 干杯!

您需要在帖子正文中發送請求,確保告訴郵遞員其內容類型為 json

POST https://translation.googleapis.com/language/translate/v2?key=YourKey

{
  "key": "xxxxxxxxxx",
  "q": "The Great Pyramid of Giza (also known as the Pyramid of Khufu or the Pyramid of Cheops) is the oldest and largest of the three pyramids in the Giza pyramid complex.",
  "source": "en",
  "target": "es",
  "format": "text"
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM