【问题标题】:google translate api error 400谷歌翻译api错误400
【发布时间】:2018-01-04 10:37:48
【问题描述】:

在翻译网页内容时,我在谷歌翻译器 api 中遇到错误。请告诉我如何摆脱以下错误。

发出以下错误的 curl 请求

<?php
      CURLOPT_URL => 
      "https://translation.googleapis.com/language/translate/v2?key=KEY",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "POST",
      CURLOPT_POSTFIELDS => data,
      CURLOPT_HTTPHEADER => array('X-HTTP-Method-Override: GET'),
      CURLOPT_CONNECTTIMEOUT => 60,
      CURLOPT_TIMEOUT =>60,
       ));
?>

回复

{
    error: {
        code: 400,
        message: "Text too long",
        errors: [
            {
                message: "Text too long",
                domain: "global",
                reason: "invalid"
            }
        ]
    }
}

【问题讨论】:

  • $data的值是多少?

标签: php curl google-api


【解决方案1】:
{
    error: {
        code: 400,
        message: "Text too long",
        errors: [
            {
                message: "Text too long",
                domain: "global",
                reason: "invalid"
            }
        ]
    }
}

如果您阅读错误消息,它会显示“文本太长”

一次可以翻译多少数据是有限制的。如果没记错的话,这个限制大约是 5,000 个字符。

解决方案发送更少的数据。

【讨论】:

    猜你喜欢
    • 2012-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-21
    • 2016-11-03
    • 1970-01-01
    相关资源
    最近更新 更多